package o2o.web.actions.order.user;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jinyou.utils.common.*;
import jPush.dao.JPushMessage;
import notice.dao.NoticeType;
import o2o.cache.comment.OrderCommentMemory;
import o2o.cache.order.*;
import o2o.cache.postman.CityPostmanMemory;
import o2o.cache.shop.ShopMemory;
import o2o.cache.user.UserAddressMemory;
import o2o.cache.user.UserInfoMemory;
import o2o.cache.user.UserOnlineImpl;
import o2o.config.annotation.LoginUser;
import o2o.config.dao.UserDaoSql;
import o2o.config.dao.utils.DaoUtils;
import o2o.config.dao.utils.Expression;
import o2o.config.dao.utils.QueryCondition;
import o2o.dao.PO.PojoTables;
import o2o.dao.PO.common.ResultInfo;
import o2o.dao.PO.game.GAME_TYPE;
import o2o.dao.PO.order.*;
import o2o.postman.model.CityPostman;
import o2o.dao.PO.shop.COMMENT_VERIFY_STATE;
import o2o.dao.PO.shop.SHOP_SERIESSALE_TYPE;
import o2o.dao.PO.shop.ShopCommentInfo;
import o2o.company.model.ShopInfo;
import o2o.dao.PO.user.UserAddress;
import o2o.dao.PO.user.UserInfo;
import o2o.dao.VO.comment.GetOrderComment;
import o2o.dao.VO.common.FileUploadInfo;
import o2o.dao.VO.order.OrderCancelInfoVO;
import o2o.dao.VO.order.OrderCommentInfoVO;
import o2o.dao.VO.order.OrderGoodsVO;
import o2o.dao.VO.order.REFUND_APPLY_STATUS;
import o2o.dao.VO.shop.ShopCommentInfoDBVO;
import o2o.dao.VO.shop.ShopCommentInfoVO;
import o2o.dao.VO.shop.ShopInfoVO;
import o2o.service.order.user.IUserOrderService;
import o2o.system.data.PROMPTS;
import o2o.system.data.SYS_CONFIG_PATH;
import o2o.system.data.SYS_SETTINGS;
import o2o.task.image.ImageService;
import o2o.utils.BackPriceResultInfo;
import o2o.utils.MultilingualResult;
import o2o.utils.OrderUtils;
import o2o.web.actions.notice.Notice;
import o2o.web.actions.order.OrderMan;
import o2o.web.actions.order.thread.OrderThread;
import o2o.web.actions.order.thread.OverOrderThread;
import o2o.web.actions.print.PrintMan;
import o2o.web.actions.shop.ShopMan;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;

import static notice.dao.NoticeType.order;
import static o2o.system.data.PROMPTS.FAILED_SAVE_IMG;

//用户订单操作
@Controller
public class UserOrderController {

    @Autowired
    private IUserOrderService userOrderService;


    //-------------------------------------用户
    // 用户催单
    @RequestMapping(method = RequestMethod.POST, value = "/user/order/urge")
    @ResponseBody
    public String order_Urge(String token, String sysAppKey, String orderNo, String lang) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (null == orderInfo) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_EXIST, lang);
        }
        if (!user.getUsername().equalsIgnoreCase(orderInfo.getCreateUser())) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_BELONG_YOU, lang);
        }

        if (ValidateUtil.isAbsLong(orderInfo.getUserUrgeTime())) {
            return AjaxResult.errorResult("您的催单已收到，请耐心等待");
        }

        int status = orderInfo.getOrderStatus();
        if (status == ORDER_STATUS.CANCEL
                || status == ORDER_STATUS.SUBMIT
                || status == ORDER_STATUS.PAYED
                || status == ORDER_STATUS.POSTMAN_CANT_FINISH
                || status == ORDER_STATUS.SHOP_FINISH
                || status == ORDER_STATUS.POSTMAN_FINISH
                || status == ORDER_STATUS.CANCEL_BY_SYSTEM
                || status == ORDER_STATUS.PAYED_APPLY_CANCEL
                || status == ORDER_STATUS.PAYED_APPLY_PART_CANCEL
                || status == ORDER_STATUS.PAYED_CANCEL
                || status == ORDER_STATUS.PAYED_REFUND_PART_CANCEL
                || status == ORDER_STATUS.PAYED_PASS_PART_CANCEL
                || status == ORDER_STATUS.OVER) {
            // 此状态不能操作
            return MultilingualResult.errorResultV2(PROMPTS.OPERATION_NOT_ALLOWED, lang);
        }

        Long payTime = orderInfo.getPayTime();
        if (payTime == null) {
            payTime = orderInfo.getCreateTime();
        }
        if (payTime == null) {
            payTime = 0L;
        }
        Long lTime = DateUtils.getCurrTime();
        if (lTime < (payTime + SYS_SETTINGS.CAN_URGE_ORDER_TIME * 60 * 1000L)) {
            return AjaxResult.errorResult(SYS_SETTINGS.CAN_URGE_ORDER_TIME + "分钟内不可以催单");
        }
        // 更新用户催单时间，给商家、骑手发送催单
        StringBuffer sb = new StringBuffer();
        sb.append("update ").append(PojoTables.OrderInfo).append(" set userUrgeTime = ").append(DateUtils.getCurrTime())
                .append(",updateUser='").append(user.getUsername()).append("' where orderNo = '").append(orderNo).append("' and delFlag = 0");
        try {
            UserDaoSql.getInstance().executeBySql(sb.toString());
        } catch (SQLException e) {
            e.printStackTrace();
            return AjaxResult.errorResult("催单失败，请稍后再试");
        }

        // 更新缓存
        OrderInfoMemory.getInstance().modifyStatus(orderNo);

        // 通知骑手和商家
        if (ValidateUtil.isNotID(orderInfo.getShopId())) {
            ShopInfo shopInfo = ShopMemory.getInstance().getShopById(orderInfo.getShopId());
            if (null != shopInfo) {
                Notice.publishNotice2Person(sysAppKey, shopInfo.getOwnUsername(), JPushMessage.SHOP_OWNER, "-5", NoticeType.order, "用户催单", "用户催单（订单编号：" + orderNo + "），请尽快处理", orderNo);
            }
        }
        if (ValidateUtil.isNotNull(orderInfo.getPostManUsername())) {
            Notice.publishNotice2Person(sysAppKey, orderInfo.getPostManUsername(), JPushMessage.POSTMAN, "-5", NoticeType.order, "用户催单", "用户催单（订单编号：" + orderNo + "），请尽快处理", orderNo);
        }

        return AjaxResult.successResult();
    }


    //用户取消订单
    @RequestMapping(method = RequestMethod.POST, value = "/order/user/cancel")
    @ResponseBody
    public String order_cancel(String token, String sysAppKey, String orderNo, String cancelReason, String lang) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (null == orderInfo) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_EXIST, lang);
        }
        if (!user.getUsername().equalsIgnoreCase(orderInfo.getUsername())) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_BELONG_YOU, lang);
        }

        OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderNo);
        if (null != orderPayInfo && 0 == 1 - orderPayInfo.getIsPaid()) {
            return MultilingualResult.errorResultV2(PROMPTS.PAID_APPLY_REFUND, lang);
        }
        // 货到付款订单
        if (orderInfo.getIsArrivePay() != null && 1 - orderInfo.getIsArrivePay() == 0
                && (orderInfo.getOrderStatus() != ORDER_STATUS.SUBMIT && orderInfo.getOrderStatus() != ORDER_STATUS.ARRIVE_PAY)) {
            System.out.println(orderInfo.getOrderNo() + ":\t" + "商户已经接单");
            return AjaxResult.errorResult("货到付款订单，请申请退款");
        }
        ResultInfo resultInfo = null;
        if (orderInfo.getOrderType() == ORDER_TYPE.SHOP_SERVICE) {

        } else {
            resultInfo = OrderMan.cancelOrderDirect(orderInfo, user.getUsername(), cancelReason, ORDER_STATUS.CANCEL, false, true);
        }
        //取消订单
        if (null != resultInfo && !resultInfo.isSuccess()) {
            return AjaxResult.errorResult(resultInfo.getError());
        }
        Notice.publishNotice2Person(sysAppKey, user.getUsername(), JPushMessage.USER, order, "订单信息", "您的订单（订单编号：" + orderNo + "），已取消");
        return AjaxResult.successResult();
    }

    //用户确认完成--完成订单
    @RequestMapping(method = RequestMethod.POST, value = "/order/user/finish")
    @ResponseBody
    public String order_finish(String token, String sysAppKey, String orderNo, String lang) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (null == orderInfo) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_EXIST, lang);
        }
        if (!user.getUsername().equalsIgnoreCase(orderInfo.getCreateUser())) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_BELONG_YOU, lang);
        }
        int status = orderInfo.getOrderStatus();
        if (status == ORDER_STATUS.CANCEL
                || status == ORDER_STATUS.SUBMIT
                || status == ORDER_STATUS.OVER) {
            return MultilingualResult.errorResultV2(PROMPTS.OPERATION_NOT_ALLOWED, lang);
        }
        //商家确认接单两小时后  可以确认完成
        if (status == ORDER_STATUS.PEISONG
                || status == ORDER_STATUS.POSTMAN_SURE
                || status == ORDER_STATUS.POSTMAN_ZHIDING
                || status == ORDER_STATUS.POSTMAN_REFUSED
                || status == ORDER_STATUS.POSTMAN_CANT_FINISH
                || status == ORDER_STATUS.SHOP_REFUSED
                || status == ORDER_STATUS.SHOP_SURE) {
            if (DateUtils.getCurrTime() - orderInfo.getShopSureTime() < 2 * 60 * 60 * 1000)
                return MultilingualResult.errorResultV2(PROMPTS.OPERATION_NOT_ALLOWED, lang);
        }

        OrderMan.finishOrder(orderNo, user.getUsername(), orderInfo);
        Notice.publishNotice2Person(sysAppKey, user.getUsername(), JPushMessage.USER, order, "订单信息", "您的订单（订单编号：" + orderNo + "），已确认完成，可以去评价了");

        //跑腿订单 更新跑腿订单信息里的状态
        if (null != orderInfo.getOrderType() && (
                0 == ORDER_TYPE.PAO_TUI - orderInfo.getOrderType()
                        || 0 == ORDER_TYPE.DAI_GOU - orderInfo.getOrderType()
                        || 0 == ORDER_TYPE.BANG_BAN - orderInfo.getOrderType()
                        || 0 == ORDER_TYPE.HUO_YUN - orderInfo.getOrderType())
        ) {//跑腿订单
            StringBuilder sbOther = new StringBuilder();
            sbOther.append("update ").append(PojoTables.OTHER_ORDER_INFO).append(" set  orderStatus=").append(ORDER_STATUS.OVER).append(",updateUser='")
                    .append(user.getUsername()).append("' where delFlag =0 and  orderNo = '").append(orderNo).append("'");
            try {
                UserDaoSql.getInstance().executeBySql(sbOther.toString());
            } catch (SQLException e) {
                e.printStackTrace();
                return MultilingualResult.errorResultV2(PROMPTS.UPDATE_ORDER_STATUS_FAILED, lang);
            }
            //缓存修改
            OtherOrderMemory.getInstance().addOrModify(orderNo);
        }
        return AjaxResult.successResult();
    }


    //删除订单
    //用户删除订单
    @RequestMapping(method = RequestMethod.POST, value = "/order/user/del")
    @ResponseBody
    public String order_del(String token, String sysAppKey, String orderNo, String lang) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (null == orderInfo) {
//            return AjaxResult.errorResult("该订单不存在");
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_EXIST, lang);
        }
        if (!user.getUsername().equalsIgnoreCase(orderInfo.getUsername())) {
//            return AjaxResult.errorResult("该订单不是您提交的");
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_BELONG_YOU, lang);
        }
        if (1 == orderInfo.getUserDel()) {
//            return AjaxResult.errorResult("该订单已删除,请勿重复操作");
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_ALREADY_DEL, lang);
        }

        int status = orderInfo.getOrderStatus();
        if (status == ORDER_STATUS.PEISONG
                || status == ORDER_STATUS.POSTMAN_ZHIDING
                || status == ORDER_STATUS.POSTMAN_SURE
                || status == ORDER_STATUS.POSTMAN_FINISH
                || status == ORDER_STATUS.POSTMAN_CANT_FINISH
                || status == ORDER_STATUS.SHOP_FINISH
                || status == ORDER_STATUS.SHOP_REFUSED
                || status == ORDER_STATUS.SHOP_SURE) {
//            return AjaxResult.errorResult("当前状态下不允许删除订单");
            return MultilingualResult.errorResultV2(PROMPTS.OPERATION_NOT_ALLOWED, lang);
        }
        // 用户只是提交了订单  但是未支付的情况下 需要将订单直接取消掉
        if (status == ORDER_STATUS.SUBMIT) {
            // 取消了订单
            ResultInfo resultInfo = OrderMan.cancelOrderDirect(orderInfo, user.getUsername(), "用户删除订单~~~", ORDER_STATUS.CANCEL, false, true);
            if (null != resultInfo && !resultInfo.isSuccess()) {
                return AjaxResult.errorResult("删除订单失败,请稍后重试~~");
            }
        }
//        orderInfo.getOrderType() == ORDER_TYPE.HUO_YUN;
        Connection conn = null;
        try {
            conn = UserDaoSql.getInstance().getConnection();
            conn.setAutoCommit(false);
        } catch (Exception e) {
            return MultilingualResult.errorResultV2(PROMPTS.DELETE_ORDER_FAILED, lang);
        }
        boolean isPaoTui = false;
        if (orderInfo.getOrderType() != null
                && (orderInfo.getOrderType() == ORDER_TYPE.HUO_YUN
                || orderInfo.getOrderType() == ORDER_TYPE.BANG_BAN
                || orderInfo.getOrderType() == ORDER_TYPE.DAI_GOU
                || orderInfo.getOrderType() == ORDER_TYPE.PAO_TUI)) {
            isPaoTui = true;
        }
        StringBuilder sb = new StringBuilder();
        sb.append("update ").append(PojoTables.OrderInfo).append(" set userDel = 1,updateUser = '")
                .append(user.getUsername()).append("' where orderNo = '").append(orderNo).append("' and delFlag = 0 and userDel = 0");
        StringBuffer sql = new StringBuffer();
        if (isPaoTui) {
            sql.append("update ").append(PojoTables.OTHER_ORDER_INFO)
                    .append(" set userDel = 1").append(" where orderNo = '").append(orderNo).append("'");
        }
        try {
            UserDaoSql.getInstance().executeBySql(sb.toString(), conn);
            if (isPaoTui) {
                UserDaoSql.getInstance().executeBySql(sql.toString(), conn);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.DELETE_ORDER_FAILED, lang);
        }

        try {
            conn.commit();
        } catch (Exception e) {
            e.printStackTrace();
            UserDaoSql.getInstance().rollback(conn);
            return MultilingualResult.errorResultV2(PROMPTS.DELETE_ORDER_FAILED, lang);
        } finally {
            UserDaoSql.getInstance().close(conn);
        }
        OrderInfoMemory.getInstance().userDelOrder(orderNo);
        if (isPaoTui) {
            // 删除;只是用户删除了  并没有真的删除了订单
//            OtherOrderMemory.getInstance().del(orderNo);//删除
        }
        return AjaxResult.successResult();
    }


    //用户 申请 取消订单(商家已接单)
    @RequestMapping(method = RequestMethod.POST, value = {"/order/user/cancel/apply", "/group/order/user/cancel"})
    @ResponseBody
    public String order_cancel_apply(String token, String sysAppKey, String orderNo, String cancelReason, String lang) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (null == orderInfo) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_EXIST, lang);
        }
        if (!user.getUsername().equalsIgnoreCase(orderInfo.getUsername())) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_BELONG_YOU, lang);
        }

        if ((orderInfo.getOrderType() == null || orderInfo.getOrderType() != ORDER_TYPE.GROUP_ORDER)
                && (ORDER_STATUS.OVER == orderInfo.getOrderStatus()
                || ORDER_STATUS.CANCEL_BY_SYSTEM == orderInfo.getOrderStatus()
                || ORDER_STATUS.PAYED_CANCEL == orderInfo.getOrderStatus()
                || ORDER_STATUS.SUBMIT == orderInfo.getOrderStatus()
                || ORDER_STATUS.CANCEL == orderInfo.getOrderStatus()
                || ORDER_STATUS.POSTMAN_FINISH == orderInfo.getOrderStatus()
        )) {
            return MultilingualResult.errorResultV2(PROMPTS.OPERATION_NOT_ALLOWED, lang);
        }

        // 团购订单
        if (orderInfo.getOrderType() != null && orderInfo.getOrderType() == ORDER_TYPE.GROUP_ORDER) {
            ResultInfo resultInfo = OrderMan.cancelGroupOrder(sysAppKey, orderInfo, cancelReason, user.getUsername());
            if (null == resultInfo) {
                return MultilingualResult.errorResultV2(PROMPTS.OPERATION_FAILED, lang);
            }
            if (!resultInfo.isSuccess()) {
                return AjaxResult.errorResult(resultInfo.getError());
            }
            Notice.publishNotice2Person(sysAppKey, user.getUsername(), JPushMessage.USER, NoticeType.order, "订单信息", "您的订单（订单编号：" + orderNo + "），已取消");
            return AjaxResult.successResult();
        }

        if (REFUND_APPLY_STATUS.NONE != orderInfo.getIsRefundApply()) {
            return MultilingualResult.errorResultV2(PROMPTS.APPLIED_ALREADY_TO_ORDER, lang);
        }

        String cancelR = "";
        if (ValidateUtil.isNotNull(cancelReason)) {
            cancelR = ",cancelReason='" + cancelReason + "'";
        }

        //订单在商家未接单时候执行/ 跑腿订单可能不需要审核 直接可以取消订单
        if (ORDER_STATUS.PAYED == orderInfo.getOrderStatus() || ORDER_STATUS.ARRIVE_PAY == orderInfo.getOrderStatus() || ORDER_STATUS.SHOP_SELECT == orderInfo.getOrderStatus()
                || (SYS_SETTINGS.PAOTUI_ORDER_REFUND_NO_NEED_VERIFY == 1 && orderInfo.getOrderType() != null && orderInfo.getOrderType() - ORDER_TYPE.PAO_TUI == 0)) {
            ResultInfo resultInfo = OrderMan.cancelOrder(sysAppKey, orderInfo, user.getUsername(), cancelReason);
            if (null == resultInfo) {
//                return AjaxResult.errorResult("操作失败，请稍后再试");
                return MultilingualResult.errorResultV2(PROMPTS.OPERATION_FAILED, lang);
            }
            if (!resultInfo.isSuccess()) {
                return AjaxResult.errorResult(resultInfo.getError());
            }
            //更新用户订单申请
            //更新订单信息
            StringBuffer sb = new StringBuffer();
            sb.append("update  ").append(PojoTables.OrderInfo).append(" set isRefundApply = ").append(REFUND_APPLY_STATUS.PASS).append(cancelR)
                    .append(",updateUser ='").append(user.getUsername()).append("'  where delFlag = 0 and orderNo = '").append(orderNo).append("'");
            try {
                UserDaoSql.getInstance().executeBySql(sb.toString());
            } catch (SQLException e) {
                e.printStackTrace();
//                return AjaxResult.errorResult("操作失败，请稍后再试");
                return MultilingualResult.errorResultV2(PROMPTS.OPERATION_FAILED, lang);
            }
            //修改订单信息缓存
            OrderInfoMemory.getInstance().modifyStatus(orderNo);
            if (ORDER_STATUS.POSTMAN_FINISH == orderInfo.getOrderStatus() || ORDER_STATUS.SHOP_FINISH == orderInfo.getOrderStatus()) {
                OverOrderThread.map.remove(orderNo);
            }
            Notice.publishNotice2Person(sysAppKey, user.getUsername(), JPushMessage.USER, NoticeType.order, "订单信息", "您的订单（订单编号：" + orderNo + "），已取消");

            return AjaxResult.successResult();
        }
        // 非扫码订单才可以的使用的
        //  商家接单后指定时间内不需要商家同意就能取消订单=
        if (ValidateUtil.isNull(orderInfo.getExtra2()) || !orderInfo.getExtra2().equals("scan_code")) {
            if (SYS_SETTINGS.NO_NEED_REFUNDS_AFTER_SHOP_SURE != null && SYS_SETTINGS.NO_NEED_REFUNDS_AFTER_SHOP_SURE > 0) {
                int seconds = SYS_SETTINGS.NO_NEED_REFUNDS_AFTER_SHOP_SURE;
                Long sureTime = orderInfo.getShopSureTime();
                if (!ValidateUtil.isAbsLong(sureTime)) {
                    sureTime = orderInfo.getPayTime();
                }
                if (ValidateUtil.isAbsLong(sureTime) && DateUtils.getCurrTime() - sureTime < seconds * 1000L) {
                    // 制定时间可以自动 取消
                    if (ValidateUtil.isNull(cancelReason)) {
                        cancelReason = "商家接单后，指定时间内取消订单";
                    }
                    ResultInfo resultInfo = OrderMan.cancelOrder(sysAppKey, orderInfo, user.getUsername(), cancelReason);
                    if (null == resultInfo) {
                        return MultilingualResult.errorResultV2(PROMPTS.OPERATION_FAILED, lang);
                    }
                    if (!resultInfo.isSuccess()) {
                        return AjaxResult.errorResult(resultInfo.getError());
                    }
                    //更新用户订单申请
                    //更新订单信息
                    StringBuffer sb = new StringBuffer();
                    sb.append("update  ").append(PojoTables.OrderInfo).append(" set isRefundApply = ").append(REFUND_APPLY_STATUS.PASS).append(cancelR)
                            .append(",updateUser ='").append(user.getUsername()).append("'  where delFlag = 0 and orderNo = '").append(orderNo).append("'");
                    try {
                        UserDaoSql.getInstance().executeBySql(sb.toString());
                    } catch (SQLException e) {
                        e.printStackTrace();
                        return MultilingualResult.errorResultV2(PROMPTS.OPERATION_FAILED, lang);
                    }
                    //修改订单信息缓存
                    OrderInfoMemory.getInstance().modifyStatus(orderNo);
                    if (ORDER_STATUS.POSTMAN_FINISH == orderInfo.getOrderStatus() || ORDER_STATUS.SHOP_FINISH == orderInfo.getOrderStatus()) {
                        OverOrderThread.map.remove(orderNo);
                    }
                    if (ValidateUtil.isID(orderInfo.getShopId())) {
                        ShopInfo shopInfo = ShopMemory.getInstance().getShopById(orderInfo.getShopId());
                        if (null != shopInfo) {
                            Notice.publishNotice2Person(sysAppKey, shopInfo.getOwnUsername(), JPushMessage.SHOP_OWNER, NoticeType.order, "订单信息", "您店铺的订单（订单编号：" + orderNo + "）已取消");
                        }
                    }
                    Notice.publishNotice2Person(sysAppKey, user.getUsername(), JPushMessage.USER, NoticeType.order, "订单信息", "您的订单（订单编号：" + orderNo + "），已取消");
                    return AjaxResult.successResult();
                }
            }
        }
        // 聚合订单
        if (OrderMan.isMultipleParentOrder(orderInfo)) {
            ResultInfo resultInfo = OrderMan.multipleOrderCancelApply(sysAppKey, orderInfo, cancelReason, user.getUsername());
            if (resultInfo == null || !resultInfo.isSuccess()) {
                return AjaxResult.errorResult(resultInfo == null ? "操作失败,请稍后重试~" : resultInfo.getError());
            }
            return AjaxResult.successResult();
        }
        // 非聚合订单~
        //更新订单信息
        StringBuffer sb = new StringBuffer();
        sb.append("update  ").append(PojoTables.OrderInfo).append(" set isRefundApply = ").append(REFUND_APPLY_STATUS.APPLY).append(cancelR)
                .append(",updateUser ='").append(user.getUsername()).append("'  where delFlag = 0 and orderNo = '").append(orderNo).append("'");
        try {
            UserDaoSql.getInstance().executeBySql(sb.toString());
        } catch (SQLException e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.APPLICATION_FAILED, lang);
        }
        //添加一条订单状态
        Long tim = DateUtils.getCurrTime();
        OrderStatus status = new OrderStatus(orderNo, ORDER_STATUS.PAYED_APPLY_CANCEL, user.getUsername(), tim);
        status.setNote(cancelReason);
        try {
            UserDaoSql.getInstance().insertObj(PojoTables.OrderStatus, status);
        } catch (SQLException e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.APPLICATION_FAILED, lang);
        }

        //修改订单信息缓存
        OrderInfoMemory.getInstance().modifyStatus(orderNo);
        //修改订单状态信息缓存
        OrderStatusMemory.getInstance().addStatus(orderNo);

        //先取消自动完成
        if (ORDER_STATUS.POSTMAN_FINISH == orderInfo.getOrderStatus() || ORDER_STATUS.SHOP_FINISH == orderInfo.getOrderStatus()) {
            OverOrderThread.map.remove(orderNo);
        }
        Notice.publishNotice2Person(sysAppKey, user.getUsername(), JPushMessage.USER, NoticeType.order, "订单信息", "您的订单（订单编号：" + orderNo + "），已申请取消，请耐心等待审核");

        // 给商家推送有退款申请
        if (ValidateUtil.isID(orderInfo.getShopId())) {
            ShopInfo shopInfo = ShopMemory.getInstance().getShopById(orderInfo.getShopId());
            if (null != shopInfo) {
                Notice.publishNotice2Person(sysAppKey, shopInfo.getOwnUsername(), JPushMessage.SHOP_OWNER, "-4", NoticeType.order, "申请退款", "您店铺的订单（订单编号：" + orderNo + "）用户申请取消订单", orderNo);
            }
        }
        // 有配送员的话，推送给配送员
        if (ValidateUtil.isNotNull(orderInfo.getPostManUsername())) {
            Notice.publishNotice2Person(sysAppKey, orderInfo.getPostManUsername(), JPushMessage.POSTMAN, "-4", NoticeType.order, "申请退款", "您的订单（订单编号：" + orderNo + "）用户申请退款", orderNo);
        }

        // 申请退款语音播报
        if (ValidateUtil.isNotNull(SYS_SETTINGS.PRINT_CANCEL_ORDER_APPLY_INSTRUCTION)) {
            PrintMan.sendApplyCancelOrderVoice(orderInfo);
        }

        return AjaxResult.successResult();
    }

    // 部分商品退款

    /**
     * 部分商品退款
     *
     * @param token
     * @param sysAppKey
     * @param orderNo
     * @return 说明
     * 零 、餐盒费问题
     * 1.若是系统有餐盒费
     * （1）在商家备货完成之前是退还打包费
     * （2）在商家备货完成之后 按照系统标识 决定是都退还部分商品打包费
     * 一。红包问题  ：
     * 1.例如 冰淇淋每个10元  10件 红包是满100减40 退一个冰淇淋 不满足红包使用情况  不让其退款
     * 2.例如 冰淇淋每个10元  20件 红包是满100减40 退一个冰淇淋 则退换商品原价格
     * 二、活动满减问题
     * 参与活动的先不让其退款
     * 三。骑手配送费问题
     * 1.若骑手配送费没有满足减免问题 配送费不参与退回（除非选择全部商品）
     * 2.若骑手配送费有满足问题
     * （1）减免部分配送费 若退换部分商品后商品总金额不足以减免部分配送费则不让其退款
     * （2）减免全部配送给  若退换部分商品后商品总金额不足以免除配送费则不让其退款
     * （3）若是退换部分商品总金额扔满足商品配送费减免或者免除则让其退款
     */
    @RequestMapping(method = RequestMethod.POST, value = "/order/part/cancel/apply")
    @ResponseBody
    public String order_same_cancel_apply(String token, String sysAppKey, String orderNo, String goodsInfoJson, FileUploadInfo fileUploadInfo
            , OrderCancelInfoVO orderCancelInfoVO
    ) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNull(orderNo)) {
            return AjaxResult.errorResult("订单编号不能为空");
        }
        // 订单
        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (null == orderInfo) {
            return AjaxResult.errorResult("该订单不存在");
        }
        // 提交者检验
        if (!user.getUsername().equalsIgnoreCase(orderInfo.getUsername())) {
            return AjaxResult.errorResult("该订单不是您提交的");
        }

        if (ORDER_STATUS.OVER == orderInfo.getOrderStatus()
                || ORDER_STATUS.CANCEL_BY_SYSTEM == orderInfo.getOrderStatus()
                || ORDER_STATUS.PAYED_APPLY_CANCEL == orderInfo.getOrderStatus()
                || ORDER_STATUS.PAYED_CANCEL == orderInfo.getOrderStatus()
                || ORDER_STATUS.SUBMIT == orderInfo.getOrderStatus()
                || ORDER_STATUS.PAYED == orderInfo.getOrderStatus()
                || ORDER_STATUS.OVER == orderInfo.getOrderStatus()
        ) {
            return AjaxResult.errorResult("此状态下不允许操作");
        }
        if (orderInfo.getIsRefundApply() - REFUND_APPLY_STATUS.APPLY == 0
                || orderInfo.getIsRefundApply() - REFUND_APPLY_STATUS.PASS == 0) {
            return AjaxResult.errorResult("您已经申请取消了订单");
        }
        int alreadyApplyTotalCount = 0;
        double alreadyApplyTotalMoney = 0.0d;
        // 是否已经申请过了呢
        if (SYS_SETTINGS.ORDER_CAN_PART_CANCEL_MULTI == 1) {
            if (orderInfo.getIsPartCancelApply() != null && orderInfo.getIsPartCancelApply() == REFUND_APPLY_STATUS.APPLY) {
                return AjaxResult.errorResult("您已申请，无需重复操作");
            } else {
                // 未申请过 申请通过  申请被拒绝
                List<OrderCancelInfo> cancelInfoList = OrderCancelInfoMemory.getInstance().getOrderCancelInfoByParentOrderNo(orderNo, null);
                if (ValidateUtil.isAbsList(cancelInfoList)) {
                    cancelInfoList = cancelInfoList.stream().filter(bean -> bean != null
                            && (bean.getIsPartCancelApply() == REFUND_APPLY_STATUS.APPLY || bean.getIsPartCancelApply() == REFUND_APPLY_STATUS.PASS)).collect(Collectors.toList());
                    if (ValidateUtil.isAbsList(cancelInfoList)) {
                        for (OrderCancelInfo info : cancelInfoList) {
                            alreadyApplyTotalMoney = JYMathDoubleUtils.add(alreadyApplyTotalMoney, info.getBackTotalMoney() == null ? 0.0d : info.getBackTotalMoney());
                            alreadyApplyTotalCount += info.getBackTotalCount() == null ? 0 : info.getBackTotalCount();
                        }
                    }
                }
            }
        } else if (orderInfo.getIsPartCancelApply() != null && orderInfo.getIsPartCancelApply() != 0) {
            if (orderInfo.getIsPartCancelApply() == REFUND_APPLY_STATUS.APPLY) {
                return AjaxResult.errorResult("您已申请，无需重复操作");
            } else {
                return AjaxResult.errorResult("请选择取消订单");
            }
        }
        // 店铺
        ShopInfo shopInfo = ShopMemory.getInstance().getShopById(orderInfo.getShopId());
        if (ValidateUtil.isNull(shopInfo)) {
            return AjaxResult.errorResult("店铺信息不存在，请联系管理员");
        }
        // 商品
        if (ValidateUtil.isNull(goodsInfoJson)) {
            return AjaxResult.errorResult("申请退款商品不能为空");
        }
        Connection conn = null;
        try {
            conn = UserDaoSql.getInstance().getConnection();
            conn.setAutoCommit(false);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult("数据库连接异常");
        }
        //
        long cTime = DateUtils.getCurrTime();
        String backOrderNo = OrderUtils.getOrderNo();
        // 商品处理
        BackPriceResultInfo resultInfo = OrderMan.doBackGoods(orderInfo, goodsInfoJson, true, orderNo, backOrderNo, user.getUsername(), cTime, alreadyApplyTotalCount, conn);
        if (resultInfo == null) {
            UserDaoSql.getInstance().rollback(conn);
            UserDaoSql.getInstance().close(conn);
            return AjaxResult.errorResult("信息处理失败");
        }
        if (!resultInfo.isSuccess()) {
            return AjaxResult.errorResult(resultInfo.getError());
        }
        // 已经退款的金额  和 申请中的金额
        resultInfo.setAlreadyApplyMoney(alreadyApplyTotalMoney);
        // 退还打包费 商品费等
        Double backTotalPrice = 0.0d;       //  需要退的总费用
        Double backTotalGoodsPrice = 0.0d;  //  总的商品费
        Double backTotalPacketPrice = 0.0d; //  总的打包费
        if (ORDER_STATUS.SUBMIT - orderInfo.getOrderStatus() == 0
                || ORDER_STATUS.PAYED - orderInfo.getOrderStatus() == 0) {
            backTotalPacketPrice = resultInfo.getBackTotalPacketPrice() != null ? resultInfo.getBackTotalPacketPrice() : 0.0d;
            backTotalGoodsPrice = resultInfo.getBackTotalGoodsPrice() != null ? resultInfo.getBackTotalGoodsPrice() : 0.0d;
        } else {
            backTotalGoodsPrice = resultInfo.getBackTotalGoodsPrice() != null ? resultInfo.getBackTotalGoodsPrice() : 0.0d;
            if (SYS_SETTINGS.IS_BACK_PACKET_PRICE == null || SYS_SETTINGS.IS_BACK_PACKET_PRICE == 0) {
                backTotalPacketPrice = 0.0d;
                // 不退打包费
            } else {
                backTotalPacketPrice = resultInfo.getBackTotalPacketPrice() != null ? resultInfo.getBackTotalPacketPrice() : 0.0d;
            }
        }
        backTotalPrice = JYMathDoubleUtils.add(backTotalPacketPrice, backTotalGoodsPrice);
        // 赋值
        resultInfo.setBackTotalPrice(backTotalPrice).setBackTotalGoodsPrice(backTotalGoodsPrice).setBackTotalPacketPrice(backTotalPacketPrice);
        // 活动问题
        // 处理活动信息
//        ResultInfo resultInfo1 = OrderMan.doBackGames(orderInfo, backTotalPrice, orderNo);
        resultInfo = OrderMan.doBackGames(orderInfo, resultInfo, orderNo);
        if (resultInfo == null) {
            UserDaoSql.getInstance().rollback(conn);
            UserDaoSql.getInstance().close(conn);
            return AjaxResult.errorResult("信息处理失败");
        }
        if (!resultInfo.isSuccess()) {
            return AjaxResult.errorResult(resultInfo.getError());
        }
        // 起送费问题
        if (ValidateUtil.isAbsDouble(shopInfo.getStartFree())) {
            if (JYMathDoubleUtils.sub(JYMathDoubleUtils.sub(orderInfo.getTotalGoodsMoney(), backTotalPrice), alreadyApplyTotalMoney) >= shopInfo.getStartFree()) {

            } else {
                UserDaoSql.getInstance().rollback(conn);
                UserDaoSql.getInstance().close(conn);
                return AjaxResult.errorResult("退还部分商品后不满足店铺起送费");
            }
        }
        // tui
//        Double backTotalPrice2 = resultInfo.getBackTotalPrice();
        // 运费问题
        resultInfo = OrderMan.doBackFreeYunFei(shopInfo, orderInfo, backTotalPrice, resultInfo);
        if (ValidateUtil.isNull(resultInfo)) {
            UserDaoSql.getInstance().rollback(conn);
            UserDaoSql.getInstance().close(conn);
            return AjaxResult.errorResult("申请部分商品退款失败");
        }
        if (!resultInfo.isSuccess()) {
            return AjaxResult.errorResult(resultInfo.getError());
        }
        // 重新赋值计算
        backTotalPrice = resultInfo.getBackTotalPrice(); //总的退款金额
        if (backTotalPrice < 0.0) {
            UserDaoSql.getInstance().rollback(conn);
            UserDaoSql.getInstance().close(conn);
            return AjaxResult.errorResult("退款金额不满足");
        } else {
            double t = 0.0d;
            t = JYMathDoubleUtils.sub(backTotalPrice, backTotalGoodsPrice);
            if (t > 0) {
                if (JYMathDoubleUtils.sub(t, backTotalPacketPrice) > 0) {

                } else {
                    backTotalPacketPrice = t;
                }
            } else {
                backTotalGoodsPrice = backTotalPrice;
            }
        }

        // 图片处理
        if (null != fileUploadInfo) {
            if (null != fileUploadInfo.getImage1()) {
                String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.GOODS_IMAGE, fileUploadInfo.getImage1());
                if (null == filePath) {
                    UserDaoSql.getInstance().rollback(conn);
                    UserDaoSql.getInstance().close(conn);
                    return AjaxResult.errorResult("图片1存储失败，请稍后再试");
                }
                orderCancelInfoVO.setImage1Url(filePath);
            }
            if (null != fileUploadInfo.getImage2()) {
                String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.GOODS_IMAGE, fileUploadInfo.getImage2());
                if (null == filePath) {
                    UserDaoSql.getInstance().rollback(conn);
                    UserDaoSql.getInstance().close(conn);
                    return AjaxResult.errorResult("图片2存储失败，请稍后再试");
                }
                orderCancelInfoVO.setImage2Url(filePath);
            }
            if (null != fileUploadInfo.getImage3()) {
                String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.GOODS_IMAGE, fileUploadInfo.getImage3());
                if (null == filePath) {
                    UserDaoSql.getInstance().rollback(conn);
                    UserDaoSql.getInstance().close(conn);
                    return AjaxResult.errorResult("图片3存储失败，请稍后再试");
                }
                orderCancelInfoVO.setImage3Url(filePath);
            }
            if (null != fileUploadInfo.getImage4()) {
                //存储图片
                String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.GOODS_IMAGE, fileUploadInfo.getImage4());
                if (null == filePath) {
                    UserDaoSql.getInstance().rollback(conn);
                    UserDaoSql.getInstance().close(conn);
                    return AjaxResult.errorResult("图片4存储失败，请稍后再试");
                }
                orderCancelInfoVO.setImage4Url(filePath);
            }
        }
        OrderCancelInfo orderCancelInfo = new OrderCancelInfo();
        try {
            ObjectUtils.copyPropertiesExclude(orderCancelInfoVO, orderCancelInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult("订单对象复制失败");
        }
        orderCancelInfo.setOrderNo(backOrderNo).setParentOrderNo(orderNo).setId(null).setCreateTime(DateUtils.getCurrTime()).setCreateUser(user.getUsername()).setOrderType(ORDER_TYPE.BACK_ORDER)
                .setBackTotalPacketMoney(backTotalPacketPrice).setBackTotalMoney(backTotalPrice).setBackTotalGoodsMoney(backTotalGoodsPrice).setBackTotalCount(resultInfo.getBackTotalCount())
                .setShopId(orderInfo.getShopId()).setUsername(orderInfo.getUsername()).setIsPartCancelApply(REFUND_APPLY_STATUS.APPLY);
        try {
            UserDaoSql.getInstance().saveObj(PojoTables.ORDER_CANCEL_INFO, orderCancelInfo, conn);
        } catch (Exception e) {
            e.printStackTrace();
            UserDaoSql.getInstance().rollback(conn);
            UserDaoSql.getInstance().close(conn);
            return AjaxResult.errorResult("申请失败，请稍后重试");
        }
        // 修改订单缓存
//        StringBuffer sql = new StringBuffer();
//        sql.append("update ").append(PojoTables.OrderInfo).append(" set isPartCancelApply=").append(REFUND_APPLY_STATUS.APPLY).append(",")
//                .append("'updateUser='").append(user.getUsername()).append("'").append("  where delFlag = 0 and orderNo = '").append(orderInfo.getOrderNo()).append("'");

//        StringBuffer sb = new StringBuffer();
//        sb.append("update  ").append(PojoTables.OrderInfo).append(" set isPartCancelApply = ").append(REFUND_APPLY_STATUS.PASS)
//                .append(",updateUser ='").append(user.getUsername()).append("'  where delFlag = 0 and orderNo = '").append(orderNo).append("'");
        //
//        try {
//            UserDaoSql.getInstance().executeBySql(sql.toString(), conn);
//        } catch (Exception e) {
//            e.printStackTrace();
//            UserDaoSql.getInstance().rollback(conn);
//            return AjaxResult.errorResult("申请失败，请稍红重试");
//        }

//        if (!OrderMan.modifyOrderStatus(user.getUsername(), orderNo, ORDER_STATUS.PAYED_APPLY_PART_CANCEL, ",isPartCancelApply=" + REFUND_APPLY_STATUS.APPLY)) {
//            UserDaoSql.getInstance().rollback(conn);
//            return AjaxResult.errorResult("申请失败，请稍后重试");
//        }

        String cancelR = "";
        if (ValidateUtil.isNotNull(orderCancelInfoVO.getBackReason())) {
            cancelR = ",cancelReason='" + orderCancelInfoVO.getBackReason() + "'";
        }

        StringBuffer sb = new StringBuffer();
        sb.append("update  ").append(PojoTables.OrderInfo).append(" set isPartCancelApply = ").append(REFUND_APPLY_STATUS.APPLY).append(cancelR)
                .append(",updateUser ='").append(user.getUsername()).append("'  where delFlag = 0 and orderNo = '").append(orderNo).append("'");
//        try {
//            UserDaoSql.getInstance().executeBySql(sb.toString(), conn);
//        } catch (SQLException e) {
//            e.printStackTrace();
//            UserDaoSql.getInstance().rollback(conn);
//            return AjaxResult.errorResult("申请失败，请稍后再试");
//        }

        Long tim = DateUtils.getCurrTime();
        OrderStatus status = new OrderStatus(orderNo, ORDER_STATUS.PAYED_APPLY_PART_CANCEL, user.getUsername(), tim);
        status.setNote(orderCancelInfoVO.getReBackReason());
        try {
            UserDaoSql.getInstance().executeBySql(sb.toString(), conn);
            UserDaoSql.getInstance().saveObj(PojoTables.OrderStatus, status, conn);
        } catch (SQLException e) {
            e.printStackTrace();
            UserDaoSql.getInstance().rollback(conn);
            UserDaoSql.getInstance().close(conn);
            return AjaxResult.errorResult("申请失败，请稍后重试");
        }
        try {
            conn.commit();
        } catch (Exception e) {
            e.printStackTrace();
            UserDaoSql.getInstance().rollback(conn);
            return AjaxResult.errorResult("申请退款失败，请稍红重试");
        } finally {
            UserDaoSql.getInstance().close(conn);
        }
        // 更新缓存

        //修改订单信息缓存
        OrderInfoMemory.getInstance().modifyStatus(orderNo);
        //修改订单状态信息缓存
        OrderStatusMemory.getInstance().addStatus(orderNo);
        // 订单 更新
        OrderCancelInfoMemory.getInstance().addOrderCancelInfo(backOrderNo);
        // 更新缓存 1. 退款商品
        OrderCancelGoodsMemory.getInstance().add(cTime);
        // 修改订单状态2. 修改订单状态为部分商品退款

        if (ValidateUtil.isNull(sysAppKey)) {
            sysAppKey = orderInfo.getSysAppKey();
        }
        // 推送给用户
        Notice.publishNotice2Person(sysAppKey, orderInfo.getUsername(), JPushMessage.USER, order, "订单信息", "您的订单（订单编号：" + orderNo + "），已申请退款，请耐心等待审核");
        //先取消自动完成
//        if (ORDER_STATUS.POSTMAN_FINISH == orderInfo.getOrderStatus() || ORDER_STATUS.SHOP_FINISH == orderInfo.getOrderStatus()) {
//            OverOrderThread.map.remove(orderNo);
//        }

        // 给商家推送有退款申请
        if (ValidateUtil.isID(orderInfo.getShopId())) {
            if (null != shopInfo) {
                Notice.publishNotice2Person(sysAppKey, shopInfo.getOwnUsername(), JPushMessage.SHOP_OWNER, "-4", NoticeType.order, "申请退款", "您店铺的订单（订单编号：" + orderNo + "）用户申请退款", orderNo);
            }
        }

        // 有配送员的话，推送给配送员
        if (ValidateUtil.isNotNull(orderInfo.getPostManUsername())) {
            Notice.publishNotice2Person(sysAppKey, orderInfo.getPostManUsername(), JPushMessage.POSTMAN, "-4", NoticeType.order, "申请退款", "您的订单（订单编号：" + orderNo + "）用户申请退款", orderNo);
        }

        return AjaxResult.successResult();
    }

    @RequestMapping(method = RequestMethod.POST, value = "/part/cancel/order/list")
    @ResponseBody
    public String part_cancel_order_list(String token, String orderNo, Integer isPartCancelApply) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNull(orderNo)) {
            return AjaxResult.errorResult("订单编号不能为空");
        }
        List<OrderCancelInfo> parentOrderNoList = OrderCancelInfoMemory.getInstance().getOrderCancelInfoByParentOrderNo(orderNo, isPartCancelApply);
        if (ValidateUtil.isAbsList(parentOrderNoList)) {
            List<OrderCancelInfoVO> list = new ArrayList<>();
            for (OrderCancelInfo orderInfo : parentOrderNoList) {
                OrderCancelInfoVO infoVO = OrderMan.getOrderCancelInfoVO(orderInfo);
                list.add(infoVO);
            }
            if (ValidateUtil.isAbsList(list)) {
                Collections.sort(list, Comparator.comparingLong(OrderCancelInfoVO::getId).reversed());
                return AjaxResult.successResult(list.size(), list);
            }
        } else {
            return AjaxResult.errorResult("该订单暂无退款记录，请核实");
        }
        return AjaxResult.successResult(0, null);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/part/cancel/order/info")
    @ResponseBody
    public String part_cancel_order_info(String token, String backOrderNo) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNull(backOrderNo)) {
            return AjaxResult.errorResult("订单编号不能为空");
        }
        OrderCancelInfo info = OrderCancelInfoMemory.getInstance().get(backOrderNo);
        OrderCancelInfoVO infoVO = OrderMan.getOrderCancelInfoVO(info);
        if (infoVO == null) {
            return AjaxResult.errorResult("订单信息不存在，请核实");
        }
//        OrderCancelInfoVO infoVO = new OrderCancelInfoVO();
//        try {
//            ObjectUtils.copyPropertiesExclude(info, infoVO);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return AjaxResult.errorResult("获取失败，请稍后重试");
//        }
//        List<OrderCancelGoodsInfoVO> infoVOList = OrderMan.listOfOrderCancelGoodsInfoByBackOrderNo(info.getOrderNo());
//        if (ValidateUtil.isAbsList(infoVOList)) {
//            infoVO.setCancelGoodsList(infoVOList);
//        }
        return AjaxResult.successResult(infoVO);
    }

    // 部分商品退款 - 运费检测
    public static ResultInfo doBackFreeYunFei(ShopInfo shopInfo, OrderInfo orderInfo, Double backTotalPrice) {
        if (ValidateUtil.isAbsDouble(shopInfo.getFreeYunFei())) {
            if (JYMathDoubleUtils.sub(orderInfo.getTotalGoodsMoney(), backTotalPrice) >= shopInfo.getFreeYunFei()) {

            } else {
                return new ResultInfo("退还部分商品后不满足店铺减配送费");
            }
        } else {
            // 永远不减免配送费
        }
        return new ResultInfo();
    }

    // 部分商品退款 -活动信息监测
    public static ResultInfo doBackGames(OrderInfo orderInfo, List<OrderGameRules> list, Double backTotalPrice) {
        if (ValidateUtil.isNull(orderInfo)) {
            return new ResultInfo("订单信息不能为空");
        }
        if (!ValidateUtil.isAbsList(list)) {
            return new ResultInfo("活动信息不能为空");
        }
        if (!ValidateUtil.isAbsDouble(backTotalPrice)) {
            return new ResultInfo("退款信息不能为空");
        }
        for (OrderGameRules rules : list) {
            if (rules == null) {
                continue;
            }
            if (rules.getGameType() - GAME_TYPE.GOODS == 0
                    || rules.getGameType() - GAME_TYPE.MONEY == 0
                    || rules.getGameType() - GAME_TYPE.FIRST_GOODS == 0
                    || rules.getGameType() - GAME_TYPE.FIRST_MONEY == 0) {
                // 有活动信息暂时先不让其部分商品退款
                return new ResultInfo("参与活动信息不能部分商品退款");
            } else if (rules.getGameType() - GAME_TYPE.RED_PACKET_FIRST_GOODS == 0
                    || rules.getGameType() - GAME_TYPE.RED_PACKET_FIRST_MONEY == 0
                    || rules.getGameType() - GAME_TYPE.RED_PACKET_GOODS == 0
                    || rules.getGameType() - GAME_TYPE.RED_PACKET_MONEY == 0) {
                // 红包信息
                Double rang = rules.getRang();
                if (!ValidateUtil.isAbsDouble(rang)) {
                    return new ResultInfo("活动信息有误");
                } else {
                    if (rang <= JYMathDoubleUtils.sub(orderInfo.getTotalGoodsMoney(), backTotalPrice)) {
                        // 还满足活动信息
                    } else {
                        // 退部分商品后无法满足活动信息
                        return new ResultInfo("退部分商品后，不满足红包使用金额");
                    }
                }
            }
        }
        return new ResultInfo();
    }

    // 部分商品退货处理
    public static BackPriceResultInfo doBackGoods(OrderInfo orderInfo, String goodsInfoJson, String orderNo) {
        if (null == orderInfo) {
            return new BackPriceResultInfo("订单信息不能为空");
        }
        // 退款商品
        List<OrderGoodsVO> goodsVOList;
        try {
            goodsVOList = new Gson().fromJson(goodsInfoJson, new TypeToken<List<OrderGoodsVO>>() {
            }.getType());
        } catch (Exception e) {
            e.printStackTrace();
            return new BackPriceResultInfo("商品解析失败");
        }
        if (!ValidateUtil.isAbsList(goodsVOList)) {
            return new BackPriceResultInfo("退还商品解析失败");
        }
        // 处理掉无用信息
        List<OrderGoodsVO> backGoodsVOList = new ArrayList<>();
        for (OrderGoodsVO orderGoodsVO : goodsVOList) {
            if (ValidateUtil.isNotAbsLong(orderGoodsVO.getGoodsId())) {
                continue;
            }
            if (ValidateUtil.isNotAbsInteger(orderGoodsVO.getTotalCount())) {
                continue;
            }
            backGoodsVOList.add(orderGoodsVO);
        }
        if (!ValidateUtil.isAbsList(backGoodsVOList)) {
            return new BackPriceResultInfo("暂无有效提交信息，请核实");
        }
        // 商品比较处理
        List<OrderGoods> goodsList = OrderGoodsMemory.getInstance().listOfOrderNo(orderNo);
        Map<String, OrderGoods> goodsMap = new HashMap<>();
//        if (!ValidateUtil.isAbsList(goodsList)) {
//            return new BackPriceResultInfo("获取商品信息失败");
//        } else {
//            for (OrderGoods o : goodsList) {
//                if (ValidateUtil.isNotAbsLong(o.getGoodsSpecsId())) {
//                    goodsMap.put(o.getGoodsId() + "", o);
//                } else {
//                    goodsMap.put(o.getGoodsId() + "_" + o.getGoodsSpecsId(), o);
//                }
//            }
//        }
        Integer backTotalCount = 0;
        Double backTotalPrice = 0.0D;
        Double backTotalGoodsPrice = 0.0d;
        Double backTotalPacketPrice = 0.0d;

//        for (OrderGoodsVO goodsVO : backGoodsVOList) {
//            OrderGoods temp = null;
//            if (ValidateUtil.isAbsLong(goodsVO.getGoodsSpecsId())) {
//                temp = goodsMap.get(goodsVO.getGoodsId() + "_" + goodsVO.getGoodsSpecsId());
//            } else {
//                temp = goodsMap.get(goodsVO.getGoodsId());
//            }
//            if (ValidateUtil.isNull(temp)) {
//                return new BackPriceResultInfo("订单商品中查无此商品");
//            } else {
//                if (temp.getTotalCount() < goodsVO.getTotalCount()) {
//                    return new BackPriceResultInfo("退还件数大于购买件数");
//                } else {
//                    backTotalCount += goodsVO.getTotalCount();
//                    backTotalGoodsPrice = JYMathDoubleUtils.add(backTotalGoodsPrice, goodsVO.getTotalCount() * temp.getGoodsPrice());
//                    backTotalPacketPrice = JYMathDoubleUtils.add(backTotalPacketPrice, goodsVO.getTotalCount() * temp.getPacketPrice());
//                }
//            }
//        }
        if (backTotalCount - orderInfo.getTotalCount() == 0) {
            return new BackPriceResultInfo("退还全部商品请选择退还全部商品");
        }
        backTotalPrice = JYMathDoubleUtils.add(backTotalGoodsPrice, backTotalPacketPrice);
        BackPriceResultInfo backPriceResultInfo = new BackPriceResultInfo();
        backPriceResultInfo.setBackTotalCount(backTotalCount).setBackTotalGoodsPrice(backTotalGoodsPrice).setBackTotalPacketPrice(backTotalPacketPrice).setBackTotalPrice(backTotalPrice).setOrderGoodsVOList(backGoodsVOList).setSuccess(true);
        return backPriceResultInfo;
    }


    // 用户退货
    @RequestMapping(method = RequestMethod.POST, value = "/user/order/back/extra")
    @ResponseBody
    public String order_back_expressNo(String token, OrderInfoExtra infoExtra) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNull(infoExtra.getOrderNo())) {
            return AjaxResult.errorResult("订单编号不能为空");
        }

        if (null == infoExtra.getBackNo()) {
            return AjaxResult.errorResult("退货单号不能为空");
        }
        if (null == infoExtra.getBackReason()) {
            return AjaxResult.errorResult("退货原因不能为空");
        }
        // 附表
        OrderInfoExtra orderInfoExtra = OrderInfoExtraMemory.getInstance().getOrderInfoExtraByOrderNo(infoExtra.getOrderNo());
        if (null == orderInfoExtra) {
            return AjaxResult.errorResult("未获取到订单信息");
        }


        StringBuffer sb = new StringBuffer();
        sb.append("update  ").append(PojoTables.ORDER_INFO_EXTRA).append(" set backNo = '").append(infoExtra.getBackNo())
                .append("',backReason = '").append(infoExtra.getBackReason()).append("',backTime =").append(infoExtra.getBackTime())
                .append(",updateUser ='").append(user.getUsername()).append("'  where delFlag = 0 and orderNo = '").append(infoExtra.getOrderNo()).append("'");
        try {
            UserDaoSql.getInstance().executeBySql(sb.toString());
        } catch (SQLException e) {
            e.printStackTrace();
            return AjaxResult.errorResult("操作失败，请稍后再试");
        }

        // 增加缓存
        OrderInfoExtraMemory.getInstance().modify(infoExtra.getOrderNo());


        return AjaxResult.successResult();
    }


    //-------------------------评价
    //添加对订单评论
    @RequestMapping(method = RequestMethod.POST, value = "/order/comment/add")
    @ResponseBody
    public String recommend_shop_add(String token, ShopCommentInfo info, String lang, FileUploadInfo fileUploadInfo) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
//        if (ValidateUtil.isNotID(info.getShopId())) {
//            return AjaxResult.errorResult("请选择店铺");
//        }
        if (ValidateUtil.isNull(info.getOrderNo())) {
//            return AjaxResult.errorResult("请选择订单");
            return MultilingualResult.errorResultV2(PROMPTS.PLEASE_SELECT_ORDER, lang);
        }
        if (ValidateUtil.isNull(info.getComment())) {
//            return AjaxResult.errorResult("评价信息不能为空");
            return MultilingualResult.errorResultV2(PROMPTS.EVALUATE_NOT_ALLOWED_EMPTY, lang);
        }


        //todo
        //获取订单状态  是否可以评价
        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(info.getOrderNo());
        if (null == orderInfo) {
//            return AjaxResult.errorResult("该订单不存在");
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_EXIST, lang);
        } else {
            if (0 != orderInfo.getOrderStatus() - ORDER_STATUS.OVER) {
//                return AjaxResult.errorResult("该订单尚未完成，无法评价");
                return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_COMPLETED, lang);
            }

            if (!info.getOrderNo().equalsIgnoreCase(orderInfo.getOrderNo())) {
//                return AjaxResult.errorResult("该订单不是当前店铺的，请检查");
                return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_BELONG_SHOP, lang);
            }
            //是否对订单评价过
            if (0 == 1 - orderInfo.getIsComment()) {
//                return AjaxResult.errorResult("该订单已评价过，无需再次评价");
                return MultilingualResult.errorResultV2(PROMPTS.ORDER_ALREADY_EVALUATE, lang);
            }

            if (ValidateUtil.isNotID(orderInfo.getShopId())) {
//                return AjaxResult.errorResult("该订单信息有误，无法进行评价");
                return MultilingualResult.errorResultV2(PROMPTS.ORDER_INFORMATION_IS_INCORRECT, lang);
            }
            info.setShopId(orderInfo.getShopId());
        }


        ShopInfo shopInfo = ShopMemory.getInstance().getShopById(orderInfo.getShopId());
        if (null == shopInfo) {
//            return AjaxResult.errorResult("该店铺不存在");
            return MultilingualResult.errorResultV2(PROMPTS.SHOP_NOT_EXIST, lang);
        }

        //验证店铺是否存在
//        if (ShopMemory.getInstance().notExist(info.getShopId())) {
//            return AjaxResult.errorResult("当前店铺不存在，请查证后再试");
//        }

        //存储图片
        if (null != fileUploadInfo) {
            if (null != fileUploadInfo.getImage1()) {
                //存储图片
//                String filePath = JYImageUtils.saveImage(SHOPIMAGE, fileUploadInfo.getImage1());
                String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getImage1());
                if (null == filePath) {
//                    return AjaxResult.errorResult("图片1存储失败，请稍后再试");
                    return MultilingualResult.errorResultV2(FAILED_SAVE_IMG, lang);
                }
                info.setImage1Url(filePath);
            }
            if (null != fileUploadInfo.getImage2()) {
                //存储图片
//                String filePath = JYImageUtils.saveImage(SHOPIMAGE, fileUploadInfo.getImage2());
                String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getImage2());
                if (null == filePath) {
//                    return AjaxResult.errorResult("图片1存储失败，请稍后再试");
                    return MultilingualResult.errorResultV2(FAILED_SAVE_IMG, lang);
                }
                info.setImage2Url(filePath);
            }
            if (null != fileUploadInfo.getImage3()) {
                //存储图片
//                String filePath = JYImageUtils.saveImage(SHOPIMAGE, fileUploadInfo.getImage3());
                String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getImage3());
                if (null == filePath) {
//                    return AjaxResult.errorResult("图片1存储失败，请稍后再试");
                    return MultilingualResult.errorResultV2(FAILED_SAVE_IMG, lang);
                }
                info.setImage3Url(filePath);
            }
            if (null != fileUploadInfo.getImage4()) {
                //存储图片
//                String filePath = JYImageUtils.saveImage(SHOPIMAGE, fileUploadInfo.getImage4());
                String filePath = JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getImage4());
                if (null == filePath) {
//                    return AjaxResult.errorResult("图片1存储失败，请稍后再试");
                    return MultilingualResult.errorResultV2(FAILED_SAVE_IMG, lang);
                }
                info.setImage4Url(filePath);
            }
        }

        long time = DateUtils.getCurrTime();
        info.setCreateTime(time);
        info.setDelFlag(0);
        info.setCreateUser(user.getUsername());

        info.setName(user.getName());
        if (ValidateUtil.isNotNull(user.getSignPhoto())) {
//            info.setSignPhoto(user.getSignPhoto().replace(Common.imageUrl, ""));
            info.setSignPhoto(user.getSignPhoto().replace(SYS_CONFIG_PATH.IMAGE_BASE_URL, ""));
        }

        ShopCommentInfoDBVO commentInfoVO = new ShopCommentInfoDBVO();
        try {
            ObjectUtils.copyPropertiesExclude(info, commentInfoVO, null);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //存入数据库
        try {
            UserDaoSql.getInstance().insertObj(PojoTables.ShopComment, commentInfoVO);
        } catch (SQLException e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("添加评论失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.ADD_COMMENTS_FAILED, lang);
        }

        //更新订单评价
        StringBuilder sb = new StringBuilder();
        sb.append("update ").append(PojoTables.OrderInfo).append(" set iscomment = 1 where delFlag = 0 and orderNo = ").append(info.getOrderNo());
        try {
            UserDaoSql.getInstance().executeBySql(sb.toString());
        } catch (SQLException e) {
            e.printStackTrace();
//            return AjaxResult.errorResult("评价失败，请稍后再试");
            return MultilingualResult.errorResultV2(PROMPTS.ADD_COMMENTS_FAILED, lang);
        }
        //修改订单缓存
        OrderInfoMemory.getInstance().setComment(info.getOrderNo());

        //修改店铺评论
        ShopMemory.getInstance().setComment(orderInfo.getShopId(), info);

        //修改店铺星级
        ShopMan.addShopScore(shopInfo.getId(), shopInfo.getOwnUsername(), user.getUsername(), info.getStar());

        return AjaxResult.successResult();
    }

    // todo : 根据订单获取店铺信息
    @RequestMapping(method = RequestMethod.POST, value = "/user/order/comment/shop/list")
    @ResponseBody
    public String order_shop_list(String orderNo) {
        OrderInfo info = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (info == null) {
            return AjaxResult.successResult(0, null);
        }
        Set<String> orderSet = new HashSet<>();
        if (OrderMan.isMultipleParentOrder(info) || ValidateUtil.isID(info.getSquareShopId())) {
            HashSet<String> hashSet = OrderInfoMemory.getInstance().listOfParentOrderNo(info.getOrderNo());
            if (hashSet != null && !hashSet.isEmpty()) {
                orderSet.addAll(hashSet);
            }
            orderSet.add(orderNo);
        } else {
            orderSet.add(orderNo);
        }
        Map<Long, String> map = new HashMap<>();
        Set<Long> shopSet = new HashSet<>();
        for (String tOrderNo : orderSet) {
            OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(tOrderNo);
            if (ValidateUtil.isID(orderInfo.getShopId())) {
                shopSet.add(orderInfo.getShopId());
                map.put(orderInfo.getShopId(), orderInfo.getOrderNo());
            }
            if (ValidateUtil.isID(orderInfo.getSquareShopId())) {
                shopSet.add(orderInfo.getSquareShopId());
                map.put(orderInfo.getSquareShopId(), orderInfo.getOrderNo());
            }
        }
        List<ShopInfoVO> list = new ArrayList<>();
        ShopInfoVO infoVO = null;
        if (shopSet != null && shopSet.size() > 0) {
            for (Long id : shopSet) {
                ShopInfo shop = ShopMemory.getInstance().getShopById(id);
                if (shop == null) {
                    continue;
                }
                infoVO = new ShopInfoVO();
                BeanUtils.copyProperties(shop, infoVO);
                if (ValidateUtil.isNotNull(infoVO.getImageUrl()) && ValidateUtil.isNotNetUrl(infoVO.getImageUrl())) {
                    String thumb = ImageService.getThumbnailImgUrl(infoVO.getImageUrl(), infoVO.getImgUpVer(), infoVO.getThumbnailState());
                    infoVO.setImageThumbnailUrl(thumb);
//                    infoVO.setImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + infoVO.getImageUrl());
                    infoVO.setImageUrl(ImageService.getImgUrl(shop.getImgUpVer()) + infoVO.getImageUrl());
                }
                String orderNos = map.get(shop.getId());
                if (ValidateUtil.isNotNull(orderNos)) {
                    infoVO.setOrderNos(orderNos);
                }
                list.add(infoVO);
            }
        }
        if (ValidateUtil.isAbsList(list)) {
            Collections.sort(list, Comparator.comparingInt(ShopInfoVO::getCloudShopType).reversed());
        }
        return AjaxResult.successResult(list.size(), list);
    }

    // todo 一乙多商家进行评论
    @RequestMapping(method = RequestMethod.POST, value = "/order/comment/create")
    @ResponseBody
    public String order_goods_shop_postman_add(String token, String orderNo, String commentJson, String lang) {
        // 验证用户的有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNull(orderNo)) {
            return MultilingualResult.errorResultV2(PROMPTS.PLEASE_SELECT_ORDER, lang);
        }
        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (null == orderInfo) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_EXIST, lang);
        } else {
            if (0 != orderInfo.getOrderStatus() - ORDER_STATUS.OVER) {
                return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_COMPLETED, lang);
            }
            //是否对订单评价过
            if (0 == 1 - orderInfo.getIsComment()) {
                return MultilingualResult.errorResultV2(PROMPTS.ORDER_ALREADY_EVALUATE, lang);
            }
        }
        List<OrderCommentInfoVO> commentInfoVOList;
        try {
            commentJson = commentJson.replace("\\", "");
            commentInfoVOList = new Gson().fromJson(commentJson, new TypeToken<List<OrderCommentInfoVO>>() {
            }.getType());
        } catch (Exception e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.JSON_PARSING_FAILED, lang);
        }
        if (!ValidateUtil.isAbsList(commentInfoVOList)) {
            return AjaxResult.errorResult("评论数据解析失败");
        }
        if (orderInfo.getOrderType() == ORDER_TYPE.DAI_GOU
                || orderInfo.getOrderType() == ORDER_TYPE.PAO_TUI
                || orderInfo.getOrderType() == ORDER_TYPE.PERSON_TRANSPORT
                || orderInfo.getOrderType() == ORDER_TYPE.HUO_YUN
                || orderInfo.getOrderType() == ORDER_TYPE.BANG_BAN) {
            if (orderInfo.getIsComment() == 1) {
                return AjaxResult.errorResult("订单已评论,无需重复评论");
            }
            OrderCommentInfoVO orderCommentInfoVO = null;
            for (OrderCommentInfoVO orderCommentInfo : commentInfoVOList) {
                if (orderCommentInfo == null) {
                    continue;
                }
                if (orderCommentInfo.getCommentType() != null && orderCommentInfo.getCommentType() == ORDER_COMMENT_TYPE.POSTMAN_COMMENT) {
                    orderCommentInfoVO = orderCommentInfo;
                    break;
                }
            }
            if (orderCommentInfoVO == null) {
                return AjaxResult.errorResult("请评论配送员");
            }
            if (orderCommentInfoVO.getObjUsername() == null || ValidateUtil.isNull(orderCommentInfoVO.getObjUsername())) {
                return AjaxResult.errorResult("骑手账号不能为空");
            }
            Long cTime = DateUtils.getCurrTime();
            orderCommentInfoVO.setOrderNo(orderNo);
            if (orderCommentInfoVO.getIsUnknownName() == null) {
                orderCommentInfoVO.setIsUnknownName(0);
            }
            orderCommentInfoVO.setCreateTime(cTime);
            // 评论者信息
            orderCommentInfoVO.setUsername(user.getUsername());
            orderCommentInfoVO.setName(user.getName());
            orderCommentInfoVO.setSignPhoto(user.getSignPhoto());
            try {
                UserDaoSql.getInstance().insertObj(PojoTables.ORDER_COMMENT, orderCommentInfoVO);
            } catch (SQLException e) {
                e.printStackTrace();
                return MultilingualResult.errorResultV2(PROMPTS.STORAGE_FAILED, lang);
            }
            StringBuffer sql = new StringBuffer();
            sql.append("update ").append(PojoTables.OrderInfo)
                    .append(" set ").append(" isComment = 1").append(" where delFlag = 0 and orderNo ='").append(orderNo).append("'");
            try {
                UserDaoSql.getInstance().executeBySql(sql.toString());
            } catch (Exception e) {
                e.printStackTrace();
                return AjaxResult.errorResult("评论失败,请稍后重试");
            }
            OrderInfoMemory.getInstance().modifyStatus(orderNo);
            return AjaxResult.successResult();
        }
        Set<String> orderSet = new HashSet<>();
        if (OrderMan.isMultipleParentOrder(orderInfo) || ValidateUtil.isID(orderInfo.getSquareShopId())) {
            HashSet<String> hashSet = OrderInfoMemory.getInstance().listOfParentOrderNo(orderInfo.getOrderNo());
            if (hashSet != null && !hashSet.isEmpty()) {
                orderSet.addAll(hashSet);
            }
            orderSet.add(orderNo);
        } else {
            orderSet.add(orderNo);
        }

        long time = DateUtils.getCurrTime();
        if (ValidateUtil.isAbsList(commentInfoVOList)) {
            for (int i = 0; i < commentInfoVOList.size(); i++) {
                OrderCommentInfoVO orderCommentInfoVO = commentInfoVOList.get(i);
                if (null == orderCommentInfoVO) {
                    continue;
                }
                if (orderCommentInfoVO.getCommentType() == null || (orderCommentInfoVO.getObjId() == null && orderCommentInfoVO.getObjUsername() == null)) {
                    return AjaxResult.errorResult("评论参数错误");
                }
                orderCommentInfoVO.setOrderNo(orderNo);
                if (ValidateUtil.isNull(orderCommentInfoVO.getOrderNo())) {
                    continue;
                }
                if (!orderSet.contains(orderNo)) {
                    continue;
                }
                if (orderCommentInfoVO.getIsUnknownName() == null) {
                    orderCommentInfoVO.setIsUnknownName(1);
                }
                orderCommentInfoVO.setCreateTime(time);
                // 评论者信息
                orderCommentInfoVO.setUsername(user.getUsername());
                orderCommentInfoVO.setName(user.getName());
                orderCommentInfoVO.setSignPhoto(user.getSignPhoto());
                // 设置id 和 账户
                if (orderCommentInfoVO.getCommentType() == ORDER_COMMENT_TYPE.SHOP_COMMENT) {
                    // 店铺
                    ShopInfo shopById = ShopMemory.getInstance().getShopById(orderCommentInfoVO.getObjId());
                    if (null != shopById) {
                        orderCommentInfoVO.setObjUsername(shopById.getOwnUsername());
                    } else {
                        continue;
                    }
                } else if (orderCommentInfoVO.getCommentType() == ORDER_COMMENT_TYPE.POSTMAN_COMMENT) {
                    if (ValidateUtil.isNull(orderInfo.getPostManUsername())) {
                        continue;
                    }
                    CityPostman postman = CityPostmanMemory.getInstance().getPostman(orderInfo.getPostManUsername());
                    if (postman == null) {
                        continue;
                    }
                    orderCommentInfoVO.setObjUsername(postman.getUsername());
                    orderCommentInfoVO.setObjId(postman.getId());
                } else {
                    continue;
                }
                if (orderCommentInfoVO.getObjId() == null || orderCommentInfoVO.getObjUsername() == null) {
                    return AjaxResult.errorResult("信息不全，无法评价");
                }
                //店铺评论修改缓存
                if (commentInfoVOList.get(i).getCommentType() == ORDER_COMMENT_TYPE.SHOP_COMMENT) {
                    ShopCommentInfo shopCommentInfo = new ShopCommentInfo();
                    BeanUtils.copyProperties(orderCommentInfoVO, shopCommentInfo);
                    shopCommentInfo.setShopId(orderCommentInfoVO.getObjId());
                    //店铺评论 添加另一个表
                    try {
                        shopCommentInfo.setCreateUser(user.getUsername());
                        UserDaoSql.getInstance().insertObj(PojoTables.ShopComment, shopCommentInfo);
                    } catch (SQLException e) {
                        e.printStackTrace();
                        return MultilingualResult.errorResultV2(PROMPTS.STORAGE_FAILED, lang);
                    }
                    //修改店铺评论
                    ShopMemory.getInstance().setComment(orderInfo.getShopId(), shopCommentInfo);
                    //修改店铺星级
                    ShopMan.addShopScore(shopCommentInfo.getShopId(), orderCommentInfoVO.getObjUsername(), user.getUsername(), shopCommentInfo.getStar());
                } else if (commentInfoVOList.get(i).getCommentType() == ORDER_COMMENT_TYPE.POSTMAN_COMMENT) {
                }
                // 存评论
                try {
                    UserDaoSql.getInstance().insertObj(PojoTables.ORDER_COMMENT, orderCommentInfoVO);
                } catch (SQLException e) {
                    e.printStackTrace();
                    return MultilingualResult.errorResultV2(PROMPTS.STORAGE_FAILED, lang);
                }
            }
            //更新订单评价
            StringBuilder sb = new StringBuilder();
            sb.append("update ").append(PojoTables.OrderInfo).append(" set isComment = 1 where delFlag = 0 and orderNo in ('").append(StringUtils.join(orderSet, ",")).append("')");
            try {
                UserDaoSql.getInstance().executeBySql(sb.toString());
            } catch (SQLException e) {
                e.printStackTrace();
                return MultilingualResult.errorResultV2(PROMPTS.ADD_COMMENTS_FAILED, lang);
            }
            //修改订单缓存
            for (String t : orderSet) {
                OrderInfoMemory.getInstance().setComment(orderNo);
            }
        }
        return AjaxResult.successResult();
    }


    // 添加对商品/店铺/配送员的评论
    @RequestMapping(method = RequestMethod.POST, value = "/order/comment/add/v2")
    @ResponseBody
    public String order_goods_shop_postman_add(String token, String orderNo, Integer isUnknownName, String commentJson, String lang, FileUploadInfo fileUploadInfo, OrderCommentInfoVO commen) {
        // 验证用户的有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNull(orderNo)) {
            return MultilingualResult.errorResultV2(PROMPTS.PLEASE_SELECT_ORDER, lang);
        }
        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (null == orderInfo) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_EXIST, lang);
        } else {
            if (0 != orderInfo.getOrderStatus() - ORDER_STATUS.OVER) {
                return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_COMPLETED, lang);
            }

            if (!orderNo.equalsIgnoreCase(orderInfo.getOrderNo())) {
                return MultilingualResult.errorResultV2(PROMPTS.ORDER_NOT_BELONG_SHOP, lang);
            }
            //是否对订单评价过
            if (0 == 1 - orderInfo.getIsComment()) {
                return MultilingualResult.errorResultV2(PROMPTS.ORDER_ALREADY_EVALUATE, lang);
            }
        }
        List<OrderCommentInfoVO> commentInfoVOList;
        try {
            commentJson = commentJson.replace("\\", "");
            commentInfoVOList = new Gson().fromJson(commentJson, new TypeToken<List<OrderCommentInfoVO>>() {
            }.getType());
        } catch (Exception e) {
            e.printStackTrace();
            return MultilingualResult.errorResultV2(PROMPTS.JSON_PARSING_FAILED, lang);
        }
        if (!ValidateUtil.isAbsList(commentInfoVOList)) {
            return AjaxResult.errorResult("评论数据解析失败");
        }

        if (orderInfo.getOrderType() == ORDER_TYPE.DAI_GOU
                || orderInfo.getOrderType() == ORDER_TYPE.PAO_TUI
                || orderInfo.getOrderType() == ORDER_TYPE.PERSON_TRANSPORT
                || orderInfo.getOrderType() == ORDER_TYPE.HUO_YUN
                || orderInfo.getOrderType() == ORDER_TYPE.BANG_BAN) {
            if (orderInfo.getIsComment() == 1) {
                return AjaxResult.errorResult("订单已评论,无需重复评论");
            }
            OrderCommentInfoVO orderCommentInfoVO = null;
            for (OrderCommentInfoVO orderCommentInfo : commentInfoVOList) {
                if (orderCommentInfo == null) {
                    continue;
                }
                if (orderCommentInfo.getCommentType() != null && orderCommentInfo.getCommentType() == ORDER_COMMENT_TYPE.POSTMAN_COMMENT) {
                    orderCommentInfoVO = orderCommentInfo;
                    break;
                }
            }
            if (orderCommentInfoVO == null) {
                return AjaxResult.errorResult("请评论配送员");
            }
            if (orderCommentInfoVO.getObjUsername() == null || ValidateUtil.isNull(orderCommentInfoVO.getObjUsername())) {
                return AjaxResult.errorResult("骑手账号不能为空");
            }
            Long cTime = DateUtils.getCurrTime();
            orderCommentInfoVO.setOrderNo(orderNo);
            if (isUnknownName == null) {
                orderCommentInfoVO.setIsUnknownName(0);
            } else {
                orderCommentInfoVO.setIsUnknownName(isUnknownName);
            }
            orderCommentInfoVO.setCreateTime(cTime);
            // 评论者信息
            orderCommentInfoVO.setUsername(user.getUsername());
            orderCommentInfoVO.setName(user.getName());
            orderCommentInfoVO.setSignPhoto(user.getSignPhoto());
            try {
                UserDaoSql.getInstance().insertObj(PojoTables.ORDER_COMMENT, orderCommentInfoVO);
            } catch (SQLException e) {
                e.printStackTrace();
                return MultilingualResult.errorResultV2(PROMPTS.STORAGE_FAILED, lang);
            }
            StringBuffer sql = new StringBuffer();
            sql.append("update ").append(PojoTables.OrderInfo)
                    .append(" set ").append(" isComment = 1").append(" where delFlag = 0 and orderNo ='").append(orderNo).append("'");
            try {
                UserDaoSql.getInstance().executeBySql(sql.toString());
            } catch (Exception e) {
                e.printStackTrace();
                return AjaxResult.errorResult("评论失败,请稍后重试");
            }
            OrderInfoMemory.getInstance().modifyStatus(orderNo);
            return AjaxResult.successResult();
        }

        if (ValidateUtil.isNotID(orderInfo.getShopId())) {
            return MultilingualResult.errorResultV2(PROMPTS.ORDER_INFORMATION_IS_INCORRECT, lang);
        }
        ShopInfo shopInfo = ShopMemory.getInstance().getShopById(orderInfo.getShopId());
        if (null == shopInfo) {
            return MultilingualResult.errorResultV2(PROMPTS.SHOP_NOT_EXIST, lang);
        }
        long time = DateUtils.getCurrTime();
        if (ValidateUtil.isAbsList(commentInfoVOList)) {
            // 获取订单下的评论
            Map<String, OrderCommentInfo> commentInfoMap = OrderCommentMemory.getInstance().getOrderCommentListByOrderNoV2(orderNo);
            for (int i = 0; i < commentInfoVOList.size(); i++) {
                OrderCommentInfoVO orderCommentInfoVO = commentInfoVOList.get(i);
                if (null == orderCommentInfoVO) {
                    continue;
                }
                if (orderCommentInfoVO.getCommentType() == null || (orderCommentInfoVO.getObjId() == null && orderCommentInfoVO.getObjUsername() == null)) {
                    return AjaxResult.errorResult("评论参数错误");
                }
                orderCommentInfoVO.setOrderNo(orderNo);
                orderCommentInfoVO.setIsUnknownName(isUnknownName);

                orderCommentInfoVO.setCreateTime(time);
                // 评论者信息
                orderCommentInfoVO.setUsername(user.getUsername());
                orderCommentInfoVO.setName(user.getName());
                orderCommentInfoVO.setSignPhoto(user.getSignPhoto());

                // 设置id 和 账户
                if (orderCommentInfoVO.getCommentType() == ORDER_COMMENT_TYPE.SHOP_COMMENT) {
                    if (commentInfoMap != null && commentInfoMap.get(orderCommentInfoVO.getCommentType() + "_" + orderCommentInfoVO.getObjId()) != null) {
                        return AjaxResult.errorResult("您已经评论过了，无需再次评论");
                    }
                    // 店铺
                    ShopInfo shopById = ShopMemory.getInstance().getShopById(orderCommentInfoVO.getObjId());
                    if (null != shopById) {
                        orderCommentInfoVO.setObjUsername(shopById.getOwnUsername());
                    } else {
                        return AjaxResult.errorResult("暂无此商铺");
                    }

                    //  存储店铺图片
                    if (null != fileUploadInfo) {
                        orderCommentInfoVO.setImage1Url(commen.getImage1Url());
                        orderCommentInfoVO.setImage2Url(commen.getImage2Url());
                        orderCommentInfoVO.setImage3Url(commen.getImage3Url());
                        orderCommentInfoVO.setImage4Url(commen.getImage4Url());
                        if (null != fileUploadInfo.getImage1() || ValidateUtil.isNotNull(fileUploadInfo.getBase64Img01())) {
                            //存储图片
                            String filePath = null != fileUploadInfo.getImage1() ? JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getImage1()) : JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getBase64Img01());
                            if (null == filePath) {
                                return MultilingualResult.errorResultV2(FAILED_SAVE_IMG, lang);
                            }
                            orderCommentInfoVO.setImage1Url(filePath);
                        }
                        if (null != fileUploadInfo.getImage2() || ValidateUtil.isNotNull(fileUploadInfo.getBase64Img02())) {
                            //存储图片
                            String filePath = null != fileUploadInfo.getImage1() ? JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getImage2()) : JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getBase64Img02());
                            if (null == filePath) {
                                return MultilingualResult.errorResultV2(FAILED_SAVE_IMG, lang);
                            }
                            orderCommentInfoVO.setImage2Url(filePath);
                        }
                        if (null != fileUploadInfo.getImage3() || ValidateUtil.isNotNull(fileUploadInfo.getBase64Img03())) {
                            //存储图片
                            String filePath = null != fileUploadInfo.getImage3() ? JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getImage3()) : JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getBase64Img03());
                            if (null == filePath) {
                                return MultilingualResult.errorResultV2(FAILED_SAVE_IMG, lang);
                            }
                            orderCommentInfoVO.setImage3Url(filePath);
                        }
                        if (null != fileUploadInfo.getImage4() || ValidateUtil.isNotNull(fileUploadInfo.getBase64Img04())) {
                            //存储图片
                            String filePath = null != fileUploadInfo.getImage4() ? JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getImage4()) : JYImageUtils.saveImage(SYS_CONFIG_PATH.SHOP_IMAGE, fileUploadInfo.getBase64Img04());
                            if (null == filePath) {
                                return MultilingualResult.errorResultV2(FAILED_SAVE_IMG, lang);
                            }
                            orderCommentInfoVO.setImage4Url(filePath);
                        }
                    }
                } else if (orderCommentInfoVO.getCommentType() == ORDER_COMMENT_TYPE.POSTMAN_COMMENT) {
                    // 骑手
                    if (orderInfo.getIsZiQu() == 0) {
                        // 非自取
                        ShopInfo shopById = ShopMemory.getInstance().getShopById(orderInfo.getShopId());
                        if (shopById.getIsSelfPost() == 1) {
                            //自配送
                            if (shopById != null) {
                                orderCommentInfoVO.setObjUsername(shopById.getOwnUsername());
                                orderCommentInfoVO.setObjId(shopById.getId());
                                if (commentInfoMap != null && commentInfoMap.get(orderCommentInfoVO.getCommentType() + "_" + orderCommentInfoVO.getObjId()) != null) {
                                    return AjaxResult.errorResult("您已经评论过了，无需再次评论");
                                }
                            } else {
                                return AjaxResult.errorResult("暂无此商铺");
                            }
                        } else {
                            // 骑手
                            if (orderInfo.getIsSeriesSaleShop() != SHOP_SERIESSALE_TYPE.INNER_SHOP) {
                                if (!ValidateUtil.isNull(orderInfo.getPostManUsername())) {
                                    CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(orderInfo.getPostManUsername());
                                    if (cityPostman != null) {
                                        orderCommentInfoVO.setObjUsername(cityPostman.getUsername());
                                        orderCommentInfoVO.setObjId(cityPostman.getId());
                                        if (commentInfoMap != null && commentInfoMap.get(orderCommentInfoVO.getCommentType() + "_" + orderCommentInfoVO.getObjId()) != null) {
                                            return AjaxResult.errorResult("您已经评论过了，无需再次评论");
                                        }
                                    } else {
                                        return AjaxResult.errorResult("暂无此骑手");
                                    }
                                }
                            }
                        }
                    }
                } else if (orderCommentInfoVO.getCommentType() == ORDER_COMMENT_TYPE.SEC_POSTMAN_COMMENT) {
                    if (orderInfo.getIsZiQu() == 0) {
                        // 非自取
                        ShopInfo shopById = ShopMemory.getInstance().getShopById(orderInfo.getShopId());
                        if (orderInfo.getShopSelfPost() != null && orderInfo.getShopSelfPost() != 1) {
                            if (orderInfo.getIsSeriesSaleShop() == SHOP_SERIESSALE_TYPE.INNER_SHOP || orderInfo.getIsSeriesSaleShop() == SHOP_SERIESSALE_TYPE.SERIESSALE_SHOP) {
                                String secUsername = orderInfo.getSecondaryPostManUsername();
                                if (ValidateUtil.isNotNull(secUsername)) {
                                    CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(orderInfo.getSecondaryPostManUsername());
                                    if (cityPostman != null) {
                                        orderCommentInfoVO.setObjUsername(cityPostman.getUsername());
                                        orderCommentInfoVO.setObjId(cityPostman.getId());
                                        if (commentInfoMap != null && commentInfoMap.get(orderCommentInfoVO.getCommentType() + "_" + orderCommentInfoVO.getObjId()) != null) {
                                            return AjaxResult.errorResult("您已经评论过了，无需再次评论");
                                        }
                                    } else {
                                        return AjaxResult.errorResult("暂无此骑手");
                                    }
                                }
                            }
                        }
                    }
                }
                if (orderCommentInfoVO.getObjId() == null || orderCommentInfoVO.getObjUsername() == null) {
                    return AjaxResult.errorResult("信息不全，无法评价");
                }

                //店铺评论修改缓存
                if (commentInfoVOList.get(i).getCommentType() == ORDER_COMMENT_TYPE.SHOP_COMMENT) {
                    ShopCommentInfo shopCommentInfo = new ShopCommentInfo();
                    try {
                        ObjectUtils.copyPropertiesExclude(orderCommentInfoVO, shopCommentInfo, null);
                    } catch (Exception e) {
                        e.printStackTrace();
                        continue;
                    }
                    shopCommentInfo.setShopId(orderCommentInfoVO.getObjId());
                    shopCommentInfo.setCreateUser(user.getUsername());
                    ShopCommentInfoVO vo = new ShopCommentInfoVO();
                    try {
                        ObjectUtils.copyPropertiesExclude(shopCommentInfo, vo, null);
                    } catch (Exception e) {
                        e.printStackTrace();
                        continue;
                    }
                    if (SYS_SETTINGS.ORDER_COMMENT_NEED_VERIFY == 1) {
                        shopCommentInfo.setVerifyState(COMMENT_VERIFY_STATE.COMMENT_ING);
                    }
                    //店铺评论 添加另一个表
                    try {
                        shopCommentInfo.setCreateUser(user.getUsername());
                        // UserDaoSql.getInstance().insertObj(PojoTables.ShopComment, vo);
                        UserDaoSql.getInstance().insertObj(PojoTables.ShopComment, shopCommentInfo);
                    } catch (SQLException e) {
                        e.printStackTrace();
//                        return AjaxResult.errorResult("存储失败，请稍后再试");
                        return MultilingualResult.errorResultV2(PROMPTS.STORAGE_FAILED, lang);
                    }
                    if (SYS_SETTINGS.ORDER_COMMENT_NEED_VERIFY != 1) {
                        //修改店铺评论
                        ShopMemory.getInstance().setComment(orderInfo.getShopId(), shopCommentInfo);
                    }
                    //修改店铺星级
                    ShopMan.addShopScore(shopInfo.getId(), shopInfo.getOwnUsername(), user.getUsername(), shopCommentInfo.getStar());

                } else if (commentInfoVOList.get(i).getCommentType() == ORDER_COMMENT_TYPE.POSTMAN_COMMENT) {
                    // 骑手？
                    if (orderInfo.getIsZiQu() == 1) {
                        return AjaxResult.errorResult("自取订单不能评论骑手");
                    }
                    // 自配送 评论商家
                    if (shopInfo.getIsSelfPost() == 1 || orderInfo.getPostManUsername() == null || orderInfo.getPostManUsername().equals("")) {
                        orderCommentInfoVO.setObjId(shopInfo.getId());
                    }
                }
                // 存评论
                try {
                    UserDaoSql.getInstance().insertObj(PojoTables.ORDER_COMMENT, orderCommentInfoVO);
                } catch (SQLException e) {
                    e.printStackTrace();
                    return MultilingualResult.errorResultV2(PROMPTS.STORAGE_FAILED, lang);
                }
            }

            // 指定订单的评论信息
            Map<String, OrderCommentInfo> map = OrderCommentMemory.getInstance().getOrderCommentListByOrderNoV2(orderNo);
            List<OrderGoods> goods = OrderGoodsMemory.getInstance().listOfOrderNo(orderNo);

            boolean isComment = true;
            if (null == SYS_SETTINGS.ORDER_COMMIT_TYPE || 0 == SYS_SETTINGS.ORDER_COMMIT_TYPE) {
                // 商品 店铺  骑手 是否都已经评论完成
                if (map == null) {
                    System.out.println("此算法存在错误");
                    isComment = false;
                }
                // 验证店铺
                if (map.get(ORDER_COMMENT_TYPE.SHOP_COMMENT + "_" + shopInfo.getId()) == null) {
                    isComment = false;
                }
                // 验证商品
                if (ValidateUtil.isAbsList(goods)) {
                    for (OrderGoods orderGoods : goods) {
                        if (map.get(ORDER_COMMENT_TYPE.GOODS_COMMENT + "_" + orderGoods.getGoodsId()) == null) {
                            isComment = false;
                        }
                    }
                }
                // 骑手
                if (orderInfo.getIsZiQu() == 0) {
                    // 配送
                    if (shopInfo.getIsSelfPost() == 1 && map.get(ORDER_COMMENT_TYPE.POSTMAN_COMMENT + "_" + shopInfo.getId()) == null) {
                        isComment = false;
                    } else {
                        // i
                        if (ValidateUtil.isNotNull(orderInfo.getPostManUsername())) {
                            CityPostman postman = CityPostmanMemory.getInstance().getPostman(orderInfo.getPostManUsername());
                            if (null != postman && map.get(ORDER_COMMENT_TYPE.POSTMAN_COMMENT + "_" + postman.getId()) == null) {
                                isComment = false;
                            }
                        }
                        if (ValidateUtil.isNotNull(orderInfo.getSecondaryPostManUsername())) {
                            CityPostman postman = CityPostmanMemory.getInstance().getPostman(orderInfo.getSecondaryPostManUsername());
                            if (null != postman && map.get(ORDER_COMMENT_TYPE.SEC_POSTMAN_COMMENT + "_" + postman.getId()) == null) {
                                isComment = false;
                            }
                        }
                    }
                }
            } else if (null != SYS_SETTINGS.ORDER_COMMIT_TYPE && 1 == SYS_SETTINGS.ORDER_COMMIT_TYPE) {
                // 一次性评价完了就OK
            } else if (null != SYS_SETTINGS.ORDER_COMMIT_TYPE && 2 == SYS_SETTINGS.ORDER_COMMIT_TYPE) {
                // 商品 店铺  骑手 是否都已经评论完成
                if (map == null) {
                    System.out.println("此算法存在错误");
                    isComment = false;
                }
                // 验证店铺
                if (map.get(ORDER_COMMENT_TYPE.SHOP_COMMENT + "_" + shopInfo.getId()) == null) {
                    isComment = false;
                }
                // 骑手
                if (orderInfo.getIsZiQu() == 0) {
                    // 配送
                    if (shopInfo.getIsSelfPost() == 1 && map.get(ORDER_COMMENT_TYPE.POSTMAN_COMMENT + "_" + shopInfo.getId()) == null) {
                        isComment = false;
                    } else {
                        // 骑手配送
                        if (ValidateUtil.isNotNull(orderInfo.getPostManUsername())) {
                            CityPostman postman = CityPostmanMemory.getInstance().getPostman(orderInfo.getPostManUsername());
                            if (null != postman && map.get(ORDER_COMMENT_TYPE.POSTMAN_COMMENT + "_" + postman.getId()) == null) {
                                isComment = false;
                            }
                        }
                        if (ValidateUtil.isNotNull(orderInfo.getSecondaryPostManUsername())) {
                            CityPostman postman = CityPostmanMemory.getInstance().getPostman(orderInfo.getSecondaryPostManUsername());
                            if (null != postman && map.get(ORDER_COMMENT_TYPE.SEC_POSTMAN_COMMENT + "_" + postman.getId()) == null) {
                                isComment = false;
                            }
                        }
                    }
                }
            }
            // 均评论完成
            if (isComment || orderInfo.getOrderType() == ORDER_TYPE.GROUP_ORDER) {
                //更新订单评价
                StringBuilder sb = new StringBuilder();
                sb.append("update ").append(PojoTables.OrderInfo).append(" set isComment = 1 where delFlag = 0 and orderNo = '").append(orderNo).append("'");
                try {
                    UserDaoSql.getInstance().executeBySql(sb.toString());
                } catch (SQLException e) {
                    e.printStackTrace();
                    return MultilingualResult.errorResultV2(PROMPTS.ADD_COMMENTS_FAILED, lang);
                }
                //修改订单缓存
                OrderInfoMemory.getInstance().setComment(orderNo);
            }
        }
        return AjaxResult.successResult();
    }

    // 评论前获取
    @RequestMapping(method = RequestMethod.POST, value = "/order/comment/get/iscomment")
    @ResponseBody
    public String getOrderCommentBeforeAdd(String token, String orderNo) {
        // 验证用户的有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNull(orderNo)) {
            return AjaxResult.errorResult("请选择订单");
        }
        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (ValidateUtil.isNull(orderInfo)) {
            return AjaxResult.errorResult("无效的订单");
        }
        List<GetOrderComment> list = new ArrayList<>();

        //评论类型（0是商品 1是配送员 2店铺）
        //  商品信息
        List<OrderGoods> orderGoodsList = orderInfo.getGoods();
        if (ValidateUtil.isAbsList(orderGoodsList)) {
            for (OrderGoods orderGoods : orderGoodsList) {
                if (null == orderGoods) {
                    continue;
                }
                ShopInfo shopInfo = ShopMemory.getInstance().getShopById(orderGoods.getShopId());
                GetOrderComment getOrderComment = new GetOrderComment();
                getOrderComment.setOrderNo(orderInfo.getOrderNo());
                getOrderComment.setCommentType(1L);
                if (null != shopInfo) {
                    getOrderComment.setObjUsername(shopInfo.getOwnUsername());
                }
                getOrderComment.setObjId(orderGoods.getGoodsId());
                getOrderComment.setName(orderGoods.getName());
                getOrderComment.setPrice(orderGoods.getGoodsPrice());
                getOrderComment.setTotalCount(orderGoods.getTotalCount());
                getOrderComment.setImageUrl(orderGoods.getImageUrl());
                list.add(getOrderComment);
            }
        }
        // 获取店铺
        if (ValidateUtil.isID(orderInfo.getShopId())) {
            ShopInfo shopInfo = ShopMemory.getInstance().getShopById(orderInfo.getShopId());
            if (null != shopInfo) {
                GetOrderComment getOrderComment = new GetOrderComment();
                getOrderComment.setOrderNo(orderInfo.getOrderNo());
                getOrderComment.setObjId(shopInfo.getId());
                getOrderComment.setImageUrl(shopInfo.getImageUrl());
                getOrderComment.setObjUsername(shopInfo.getOwnUsername());
                getOrderComment.setCommentType(3L);
                getOrderComment.setName(shopInfo.getShopName());
                getOrderComment.setTotalCount(orderInfo.getTotalCount());
                getOrderComment.setPrice(orderInfo.getTotalPrice());
                list.add(getOrderComment);
            }
        }
        // 配送员
        if (0 != 1 - orderInfo.getIsZiQu()) {
            // 非自取 订单
            ShopInfo shopInfo = ShopMemory.getInstance().getShopById(orderInfo.getShopId());
            if (null != shopInfo) {
                //店铺是否为自配送（自配送的订单不需要推送给配送员） 0平台派送  1自配送
                if (null != shopInfo.getIsSelfPost() && 0 == 1 - shopInfo.getIsSelfPost()) {
                    // 自配送
                    GetOrderComment getOrderComment = new GetOrderComment();
                    getOrderComment.setOrderNo(orderInfo.getOrderNo());
                    getOrderComment.setObjId(shopInfo.getId());
                    getOrderComment.setImageUrl(shopInfo.getImageUrl());
                    getOrderComment.setObjUsername(shopInfo.getOwnUsername());
                    getOrderComment.setCommentType(2L);
                    getOrderComment.setName(shopInfo.getShopName());
//                    getOrderComment.setTotalCount(orderInfo.getTotalCount());
//                    getOrderComment.setPrice(orderInfo.getTotalPrice());
                    list.add(getOrderComment);
                } else {
                    // 平台配送

                    if (orderInfo.getIsSeriesSaleShop() == SHOP_SERIESSALE_TYPE.INNER_SHOP) {
                        String secondaryPostManUsername = orderInfo.getSecondaryPostManUsername();
                        if (ValidateUtil.isNull(secondaryPostManUsername)) {
                            System.out.println("校内配送未获取到配送员信息:" + orderInfo.getOrderNo());
                        } else {
                            CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(secondaryPostManUsername);
                            if (null != cityPostman) {
                                UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(secondaryPostManUsername);
                                GetOrderComment getOrderComment = new GetOrderComment();
                                getOrderComment.setOrderNo(orderInfo.getOrderNo());
                                getOrderComment.setCommentType(4L); // 校内骑手
                                getOrderComment.setObjId(cityPostman.getId());
                                if (null != userInfo) {
                                    if (ValidateUtil.isNotNull(userInfo.getSignPhoto())) {
                                        if (ValidateUtil.isNotNetUrl(userInfo.getSignPhoto())) {
                                            getOrderComment.setImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + userInfo.getSignPhoto());
                                        } else {
                                            getOrderComment.setImageUrl(userInfo.getSignPhoto());
                                        }
                                    }
                                    getOrderComment.setName(userInfo.getName());
                                }
                                getOrderComment.setObjUsername(cityPostman.getUsername());
                                if (getOrderComment.getName() == null || "".equals(getOrderComment.getName())) {
                                    getOrderComment.setName(cityPostman.getUsername());
                                }
                                list.add(getOrderComment);
                            }
                        }
                    } else if (orderInfo.getIsSeriesSaleShop() == SHOP_SERIESSALE_TYPE.SERIESSALE_SHOP) {
                        String username = orderInfo.getPostManUsername();
                        if (null != username) {
                            CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(username);
                            if (null != cityPostman) {
                                UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(username);
                                GetOrderComment getOrderComment = new GetOrderComment();
                                getOrderComment.setOrderNo(orderInfo.getOrderNo());
                                getOrderComment.setCommentType(2L);
                                getOrderComment.setObjId(cityPostman.getId());
                                if (null != userInfo) {
                                    if (userInfo.getSignPhoto() != null && !userInfo.getSignPhoto().equals("")) {
                                        getOrderComment.setImageUrl(userInfo.getSignPhoto());
                                    }
                                    getOrderComment.setName(userInfo.getName());
                                }
                                getOrderComment.setObjUsername(cityPostman.getUsername());
                                if (getOrderComment.getName() == null || "".equals(getOrderComment.getName())) {
                                    getOrderComment.setName(cityPostman.getUsername());
                                }
                                list.add(getOrderComment);
                            }
                        } else {
                            System.out.println("配送员获取失败");
                        }

                        String secondaryPostManUsername = orderInfo.getSecondaryPostManUsername();
                        if (ValidateUtil.isNull(secondaryPostManUsername)) {
                            System.out.println("校内配送未获取到配送员信息:" + orderInfo.getOrderNo());
                        } else {
                            CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(secondaryPostManUsername);
                            if (null != cityPostman) {
                                UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(secondaryPostManUsername);
                                GetOrderComment getOrderComment = new GetOrderComment();
                                getOrderComment.setOrderNo(orderInfo.getOrderNo());
                                getOrderComment.setCommentType(4L); // 校内骑手
                                getOrderComment.setObjId(cityPostman.getId());
                                if (null != userInfo) {
                                    if (ValidateUtil.isNotNull(userInfo.getSignPhoto())) {
                                        if (ValidateUtil.isNotNetUrl(userInfo.getSignPhoto())) {
                                            getOrderComment.setImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + userInfo.getSignPhoto());
                                        } else {
                                            getOrderComment.setImageUrl(userInfo.getSignPhoto());
                                        }
                                    }
                                    getOrderComment.setName(userInfo.getName());
                                }
                                getOrderComment.setObjUsername(cityPostman.getUsername());
                                if (getOrderComment.getName() == null || "".equals(getOrderComment.getName())) {
                                    getOrderComment.setName(cityPostman.getUsername());
                                }
                                list.add(getOrderComment);
                            }
                        }
                    } else {
                        String username = orderInfo.getPostManUsername();
                        if (null != username) {
                            CityPostman cityPostman = CityPostmanMemory.getInstance().getPostman(username);
                            if (null != cityPostman) {
                                UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(username);
                                GetOrderComment getOrderComment = new GetOrderComment();
                                getOrderComment.setOrderNo(orderInfo.getOrderNo());
                                getOrderComment.setCommentType(2L);
                                getOrderComment.setObjId(cityPostman.getId());
                                if (null != userInfo) {
                                    if (ValidateUtil.isNotNull(userInfo.getSignPhoto())) {
                                        if (ValidateUtil.isNotNetUrl(userInfo.getSignPhoto())) {
                                            getOrderComment.setImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + userInfo.getSignPhoto());
                                        } else {
                                            getOrderComment.setImageUrl(userInfo.getSignPhoto());
                                        }
                                    }
//                                    if (userInfo.getSignPhoto() != null && !userInfo.getSignPhoto().equals("")) {
//                                        getOrderComment.setImageUrl(userInfo.getSignPhoto());
//                                    }
                                    getOrderComment.setName(userInfo.getName());
                                }
                                getOrderComment.setObjUsername(cityPostman.getUsername());
                                if (getOrderComment.getName() == null || "".equals(getOrderComment.getName())) {
                                    getOrderComment.setName(cityPostman.getUsername());
                                }
                                list.add(getOrderComment);
                            }
                        } else {
                            System.out.println("配送员获取失败");
                        }
                    }
                }
            }
        }
        //取出已经评论的。。。
        Map<String, OrderCommentInfo> commentInfoMap = OrderCommentMemory.getInstance().getOrderCommentListByOrderNoV2(orderNo);
        // 评论信息默认为0
        if (null != commentInfoMap) {
            for (GetOrderComment getOrderComment : list) {
                if (commentInfoMap.get(getOrderComment.getCommentType() + "_" + getOrderComment.getObjId()) != null) {
                    getOrderComment.setIsComment(1);
                    OrderCommentInfo commentInfo = commentInfoMap.get(getOrderComment.getCommentType() + "_" + getOrderComment.getObjId());
                    getOrderComment.setStar(commentInfo.getStar()).setComment(commentInfo.getComment());
                    if (ValidateUtil.isNotNull(commentInfo.getImage1Url()) && ValidateUtil.isNotNetUrl(commentInfo.getImage1Url())) {
                        getOrderComment.setImage1Url(SYS_CONFIG_PATH.IMAGE_BASE_URL + commentInfo.getImage1Url());
                    }
                    if (ValidateUtil.isNotNull(commentInfo.getImage2Url()) && ValidateUtil.isNotNetUrl(commentInfo.getImage2Url())) {
                        getOrderComment.setImage2Url(SYS_CONFIG_PATH.IMAGE_BASE_URL + commentInfo.getImage2Url());
                    }
                    if (ValidateUtil.isNotNull(commentInfo.getImage3Url()) && ValidateUtil.isNotNetUrl(commentInfo.getImage3Url())) {
                        getOrderComment.setImage3Url(SYS_CONFIG_PATH.IMAGE_BASE_URL + commentInfo.getImage3Url());
                    }
                    if (ValidateUtil.isNotNull(commentInfo.getImage4Url()) && ValidateUtil.isNotNetUrl(commentInfo.getImage4Url())) {
                        getOrderComment.setImage4Url(SYS_CONFIG_PATH.IMAGE_BASE_URL + commentInfo.getImage4Url());
                    }
                }
            }
        }
        return AjaxResult.successResult(list.size(), list);
    }

    // 用户获取评论列表
    @RequestMapping(method = RequestMethod.POST, value = "/user/comment/list")
    @ResponseBody
    public String listOfUserComment(String token, Long startTime, Long endTime, String orderNo,
                                    @RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "20") Integer size) {
        // 验证用户的有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        StringBuilder sql = new StringBuilder();
        sql.append(" from ").append(PojoTables.ShopComment)
                .append(" where delFlag = 0 and createUser='").append(user.getUsername()).append("'");
        if (ValidateUtil.isAbsLong(startTime)) {
            sql.append(" and createTime >=").append(startTime);
        }
        if (ValidateUtil.isAbsLong(startTime)) {
            sql.append(" and createTime <=").append(endTime);
        }
        if (ValidateUtil.isNotNull(orderNo)) {
            sql.append(" and orderNo '").append(orderNo).append("'");
        }
        StringBuilder countSql = new StringBuilder();
        countSql.append(" select count(*) as counts ").append(sql.toString());
        StringBuilder selectSql = new StringBuilder();
        selectSql.append(" select  * ").append(sql.toString())
                .append(" order by createTime desc limit ").append((page - 1) * size).append("," + size);
        long count = 0;
        List<ShopCommentInfo> list = null;
        try {
            count = UserDaoSql.getInstance().getCount(countSql.toString());
            list = (List<ShopCommentInfo>) UserDaoSql.getInstance().list(ShopCommentInfo.class, selectSql.toString());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult("获取失败,请稍后重试");
        }
        if (ValidateUtil.isAbsList(list)) {
            List<ShopCommentInfoVO> commentInfoVOS = list.stream().map(a -> a.convert2VO(true)).collect(Collectors.toList());
            commentInfoVOS = commentInfoVOS.stream().map(l -> {
                if (StringUtils.isNotEmpty(l.getImage1Url()) && ValidateUtil.isNotNetUrl(l.getImage1Url())) {
                    l.setImage1Url(SYS_CONFIG_PATH.IMAGE_BASE_URL + l.getImage1Url());
                }
                if (StringUtils.isNotEmpty(l.getImage2Url()) && ValidateUtil.isNotNetUrl(l.getImage2Url())) {
                    l.setImage2Url(SYS_CONFIG_PATH.IMAGE_BASE_URL + l.getImage2Url());
                }
                if (StringUtils.isNotEmpty(l.getImage3Url()) && ValidateUtil.isNotNetUrl(l.getImage3Url())) {
                    l.setImage3Url(SYS_CONFIG_PATH.IMAGE_BASE_URL + l.getImage3Url());
                }
                if (StringUtils.isNotEmpty(l.getImage4Url()) && ValidateUtil.isNotNetUrl(l.getImage4Url())) {
                    l.setImage4Url(SYS_CONFIG_PATH.IMAGE_BASE_URL + l.getImage4Url());
                }
                return l;
            }).collect(Collectors.toList());
            return AjaxResult.successResult(commentInfoVOS, count);
        }
        return AjaxResult.successResult(null, 0);
    }

    // 用户删除评论
    @RequestMapping(method = RequestMethod.POST, value = "/user/comment/del")
    @ResponseBody
    public String listOfUserComment(String token, Long id) {
        // 验证用户的有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (id == null) {
            return AjaxResult.errorResult("评论id不能为空");
        }
        QueryCondition query = QueryCondition.getInstance();
        Expression expression = Expression.getInstance();
        expression.addChild("delFlag", 0);//所有未删除的
        expression.addChild("id", id);//所有未删除的
        query.addCondition(expression);
        String sql = DaoUtils.getSql(PojoTables.ShopComment, query);
        ShopCommentInfo shopCommentInfo = null;
        try {
            shopCommentInfo = (ShopCommentInfo) UserDaoSql.getInstance().getObject(ShopCommentInfo.class, sql.toString());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult("获取评论失败" + id);
        }
        if (shopCommentInfo == null) {
            return AjaxResult.errorResult("未获取到评论信息");
        }
        if (!user.getUsername().equals(shopCommentInfo.getCreateUser())) {
            return AjaxResult.errorResult("该评论不是您提交的");
        }
        StringBuilder updateSql = new StringBuilder();
        updateSql.append(" update ").append(PojoTables.ShopComment).append(" set UpdateUser ='").append(user.getUsername()).append("'")
                .append(" , delFlag =1 ").append(" where id =").append(id).append(" and delFlag =0");
        try {
            UserDaoSql.getInstance().executeBySql(updateSql.toString());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.errorResult("操作失败，请稍后重试");
        }

        ShopMemory.getInstance().reloadCommentByShopId(shopCommentInfo.getShopId());

        return AjaxResult.successResult();
    }

    /**
     * 扫码支付订单
     *
     * @param token
     * @param shopId
     * @param orderType
     * @param money
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/order/submit/by/code")
    @ResponseBody
    public String submitOrderBySweepCode(String token, Long shopId, Long integral, Integer orderType, Double money) {
        // 验证用户的有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        if (ValidateUtil.isNotID(shopId)) {
            return AjaxResult.errorResult("店铺Id不能为空");
        }
        // 检测店铺
        ShopInfo shopInfo = ShopMemory.getInstance().getShopById(shopId);
        if (null == shopInfo) {
            return AjaxResult.errorResult("暂无此店铺请核实");
        }
        if (0 == shopInfo.getIsLock()) {
            return AjaxResult.errorResult("店铺已被锁定，无法下单");
        }
        if (0 != 1 - shopInfo.getIsWork()) {
            return AjaxResult.errorResult("店铺已打样，请核实");
        }
        if (ValidateUtil.isNotAbsDouble(money)) {
            return AjaxResult.errorResult("订单钱数不正确请核实");
        }
        if (orderType == null) {
//            orderType = ORDER_TYPE.TO_SHOP_PAYMENT;
        }
        orderType = ORDER_TYPE.SHOP_GOODS;
        // 保存订单信息
        String orderNo = OrderUtils.getOrderNo();
        Long time = DateUtils.getCurrTime();

        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setUsername(user.getUsername());
        orderInfo.setOrderStatus(ORDER_STATUS.SUBMIT);
        if (ValidateUtil.isNull(user.getName())) {
            orderInfo.setBuyer(user.getUsername());
        } else {
            orderInfo.setBuyer(user.getName());
        }
        orderInfo.setTotalMoney(money);//订单总金额
        orderInfo.setTotalGoodsMoney(money);//商品总金额
        Double integralOffsetMoney = 0.0d;
        orderInfo.setShopCity(shopInfo.getCity());


        orderInfo.setOrderType(orderType);
        orderInfo.setOrderNo(orderNo);
        orderInfo.setTotalPrice(money);//待支付金额
        orderInfo.setIntegral(integral == null ? 0L : integral);
        orderInfo.setIntegralOffsetMoney(integralOffsetMoney);
        orderInfo.setPacketPrice(0d);//餐盒费
        orderInfo.setAwardMoney(0d);//奖励总金额
        orderInfo.setPlatformAwardMoney(0d);//平台奖励金额
        orderInfo.setShopAwardMoney(0d);//商家奖励金额
        orderInfo.setTotalCount(1);//商品总个数
        orderInfo.setIsZiQu(1);
        orderInfo.setIsPaid(0);//是否已支付
        orderInfo.setShopId(shopId);
        orderInfo.setDelFlag(0);
        orderInfo.setCreateTime(time);
        orderInfo.setCreateUser(user.getUsername());
        orderInfo.setExtra2("scan_code"); // 扫码单

        //保存店铺头像和名称
        orderInfo.setShopName(shopInfo.getShopName());
        String shopImage = shopInfo.getImageUrl();
        if (ValidateUtil.isNetUrl(shopImage)) {
            shopImage = shopImage.replace(SYS_CONFIG_PATH.IMAGE_BASE_URL, "");
        }
        orderInfo.setShopImageUrl(shopImage);//店铺头像

        //订单状态
        OrderStatus orderStatus = new OrderStatus();
        orderStatus.setOrderNo(orderNo);
        orderStatus.setCreateUser(user.getUsername());
        orderStatus.setCreateTime(time);

        try {
            UserDaoSql.getInstance().insertObj(PojoTables.OrderInfo, orderInfo);
            UserDaoSql.getInstance().insertObj(PojoTables.OrderStatus, orderStatus);
        } catch (SQLException e) {
            e.printStackTrace();
            return AjaxResult.errorResult("保存订单信息失败，稍后再试");
        }
        //缓存中增加
        OrderInfoMemory.getInstance().addOrderInfo(orderNo);
        OrderStatusMemory.getInstance().addStatus(orderNo);

        //检测是否在规定时间内支付
        OrderInfo info = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        OrderThread.map.put(orderNo, info);
        OrderInfo resultInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (ValidateUtil.isNotNetUrl(resultInfo.getShopImageUrl())) {
            resultInfo.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + resultInfo.getShopImageUrl());
        }
        return AjaxResult.successResult(resultInfo);
    }

    /**
     * 用户修改订单的地址
     *
     * @param user
     * @param orderNo
     * @param addressId
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/user/order/change/address")
    @ResponseBody
    public String userModifyOrderAddress(@LoginUser UserInfo user, String orderNo, Long addressId) {
        OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(orderNo);
        if (orderInfo == null || !user.getUsername().equals(orderInfo.getUsername())) {
            return AjaxResult.errorResult("该订单不是您的");
        }
        if (orderInfo.getIsZiQu() == 1
                || orderInfo.getOrderStatus() - ORDER_STATUS.SUBMIT == 0
                || orderInfo.getOrderStatus() - ORDER_STATUS.CANCEL_BY_SYSTEM == 0
                || orderInfo.getOrderStatus() - ORDER_STATUS.CANCEL == 0
                || orderInfo.getOrderStatus() - ORDER_STATUS.PAYED_CANCEL == 0
                || orderInfo.getOrderStatus() - ORDER_STATUS.POSTMAN_FINISH == 0
                || orderInfo.getOrderStatus() - ORDER_STATUS.SHOP_FINISH == 0
                || orderInfo.getOrderStatus() - ORDER_STATUS.OVER == 0
        ) {
            return AjaxResult.errorResult("当前状态下不可操作");
        }
        UserAddress userAddress = UserAddressMemory.getInstance().getAddressInfo(addressId);
        if (userAddress == null) {
            return AjaxResult.errorResult("地址不能为空");
        }
        try {
            userOrderService.userOrderChangeAddress(orderInfo, userAddress, user.getUsername());
        } catch (Exception e) {
            e.getMessage();
            return AjaxResult.errorResult(e.getMessage());
        }
        return AjaxResult.successResult();
    }
}
